Files
backup/cmd/utils.go
T

25 lines
464 B
Go

package cmd
import (
"fmt"
"strings"
)
// isNetworkAddress checks if the address is in host:port format
func isNetworkAddress(addr string) bool {
return strings.Contains(addr, ":")
}
func formatBytes(b int64) string {
const unit = 1024
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
}