mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-07-07 03:04:03 +00:00
Update vendor, move to labstack/echo/v4 Fixes #698
This commit is contained in:
68
vendor/github.com/labstack/gommon/bytes/bytes.go
generated
vendored
68
vendor/github.com/labstack/gommon/bytes/bytes.go
generated
vendored
@ -7,12 +7,12 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
Bytes struct {
|
||||
}
|
||||
// Bytes struct
|
||||
Bytes struct{}
|
||||
)
|
||||
|
||||
const (
|
||||
B = 1 << (10 * iota)
|
||||
_ = 1.0 << (10 * iota) // ignore first value by assigning to blank identifier
|
||||
KB
|
||||
MB
|
||||
GB
|
||||
@ -22,7 +22,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
pattern = regexp.MustCompile(`(?i)^(-?\d+)([KMGTP]B?|B)$`)
|
||||
pattern = regexp.MustCompile(`(?i)^(-?\d+(?:\.\d+)?)([KMGTPE]B?|B?)$`)
|
||||
global = New()
|
||||
)
|
||||
|
||||
@ -38,29 +38,31 @@ func (*Bytes) Format(b int64) string {
|
||||
value := float64(b)
|
||||
|
||||
switch {
|
||||
case b < KB:
|
||||
return strconv.FormatInt(b, 10) + "B"
|
||||
case b < MB:
|
||||
value /= KB
|
||||
multiple = "KB"
|
||||
case b < MB:
|
||||
value /= KB
|
||||
multiple = "KB"
|
||||
case b < GB:
|
||||
value /= MB
|
||||
multiple = "MB"
|
||||
case b < TB:
|
||||
value /= GB
|
||||
multiple = "GB"
|
||||
case b < PB:
|
||||
value /= TB
|
||||
multiple = "TB"
|
||||
case b < EB:
|
||||
case b >= EB:
|
||||
value /= EB
|
||||
multiple = "EB"
|
||||
case b >= PB:
|
||||
value /= PB
|
||||
multiple = "PB"
|
||||
case b >= TB:
|
||||
value /= TB
|
||||
multiple = "TB"
|
||||
case b >= GB:
|
||||
value /= GB
|
||||
multiple = "GB"
|
||||
case b >= MB:
|
||||
value /= MB
|
||||
multiple = "MB"
|
||||
case b >= KB:
|
||||
value /= KB
|
||||
multiple = "KB"
|
||||
case b == 0:
|
||||
return "0"
|
||||
default:
|
||||
return strconv.FormatInt(b, 10) + "B"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.02f%s", value, multiple)
|
||||
return fmt.Sprintf("%.2f%s", value, multiple)
|
||||
}
|
||||
|
||||
// Parse parses human readable bytes string to bytes integer.
|
||||
@ -72,27 +74,27 @@ func (*Bytes) Parse(value string) (i int64, err error) {
|
||||
}
|
||||
bytesString := parts[1]
|
||||
multiple := parts[2]
|
||||
bytes, err := strconv.ParseInt(bytesString, 10, 64)
|
||||
bytes, err := strconv.ParseFloat(bytesString, 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch multiple {
|
||||
case "B":
|
||||
return bytes * B, nil
|
||||
default:
|
||||
return int64(bytes), nil
|
||||
case "K", "KB":
|
||||
return bytes * KB, nil
|
||||
return int64(bytes * KB), nil
|
||||
case "M", "MB":
|
||||
return bytes * MB, nil
|
||||
return int64(bytes * MB), nil
|
||||
case "G", "GB":
|
||||
return bytes * GB, nil
|
||||
return int64(bytes * GB), nil
|
||||
case "T", "TB":
|
||||
return bytes * TB, nil
|
||||
return int64(bytes * TB), nil
|
||||
case "P", "PB":
|
||||
return bytes * PB, nil
|
||||
return int64(bytes * PB), nil
|
||||
case "E", "EB":
|
||||
return int64(bytes * EB), nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Format wraps global Bytes's Format function.
|
||||
|
Reference in New Issue
Block a user