vendor: upgrade grpc-gateway to v1.3.0, dustin/go-humanize

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyu-Ho Lee
2017-11-17 14:02:13 -08:00
parent 24b19ee222
commit 6a4a30f5d1
10 changed files with 148 additions and 54 deletions

View File

@ -84,7 +84,7 @@ func humanateBytes(s uint64, base float64, sizes []string) string {
//
// See also: ParseBytes.
//
// Bytes(82854982) -> 83MB
// Bytes(82854982) -> 83 MB
func Bytes(s uint64) string {
sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"}
return humanateBytes(s, 1000, sizes)
@ -94,7 +94,7 @@ func Bytes(s uint64) string {
//
// See also: ParseBytes.
//
// IBytes(82854982) -> 79MiB
// IBytes(82854982) -> 79 MiB
func IBytes(s uint64) string {
sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"}
return humanateBytes(s, 1024, sizes)
@ -105,18 +105,27 @@ func IBytes(s uint64) string {
//
// See Also: Bytes, IBytes.
//
// ParseBytes("42MB") -> 42000000, nil
// ParseBytes("42mib") -> 44040192, nil
// ParseBytes("42 MB") -> 42000000, nil
// ParseBytes("42 mib") -> 44040192, nil
func ParseBytes(s string) (uint64, error) {
lastDigit := 0
hasComma := false
for _, r := range s {
if !(unicode.IsDigit(r) || r == '.') {
if !(unicode.IsDigit(r) || r == '.' || r == ',') {
break
}
if r == ',' {
hasComma = true
}
lastDigit++
}
f, err := strconv.ParseFloat(s[:lastDigit], 64)
num := s[:lastDigit]
if hasComma {
num = strings.Replace(num, ",", "", -1)
}
f, err := strconv.ParseFloat(num, 64)
if err != nil {
return 0, err
}