mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-10 18:57:57 +08:00
align kubo with unified golang ci linter from IPDX and rules used in boxo and other go packages addressed lint rules: - ST1000: added package comments - ST1020, ST1021, ST1022: fixed function/method comments - QF1001: applied De Morgan's law - QF1003: converted if-else chains to tagged switches - QF1004: replaced strings.Replace with strings.ReplaceAll - QF1008: simplified embedded struct field selectors - unconvert: removed unnecessary type conversions - usestdlibvars: used stdlib constants instead of literals disabled errcheck linter in .golangci.yml
47 lines
678 B
Go
47 lines
678 B
Go
// Package unit provides data size unit formatting utilities.
|
|
package unit
|
|
|
|
import "fmt"
|
|
|
|
type Information int64
|
|
|
|
const (
|
|
_ Information = iota // ignore first value by assigning to blank identifier
|
|
KB = 1 << (10 * iota)
|
|
MB
|
|
GB
|
|
TB
|
|
PB
|
|
EB
|
|
)
|
|
|
|
func (i Information) String() string {
|
|
tmp := int64(i)
|
|
|
|
// default
|
|
d := tmp
|
|
symbol := "B"
|
|
|
|
switch {
|
|
case i > EB:
|
|
d = tmp / EB
|
|
symbol = "EB"
|
|
case i > PB:
|
|
d = tmp / PB
|
|
symbol = "PB"
|
|
case i > TB:
|
|
d = tmp / TB
|
|
symbol = "TB"
|
|
case i > GB:
|
|
d = tmp / GB
|
|
symbol = "GB"
|
|
case i > MB:
|
|
d = tmp / MB
|
|
symbol = "MB"
|
|
case i > KB:
|
|
d = tmp / KB
|
|
symbol = "KB"
|
|
}
|
|
return fmt.Sprintf("%d %s", d, symbol)
|
|
}
|