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

@ -113,7 +113,7 @@ func humanateBigBytes(s, base *big.Int, sizes []string) string {
//
// See also: ParseBigBytes.
//
// BigBytes(82854982) -> 83MB
// BigBytes(82854982) -> 83 MB
func BigBytes(s *big.Int) string {
sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
return humanateBigBytes(s, bigSIExp, sizes)
@ -123,7 +123,7 @@ func BigBytes(s *big.Int) string {
//
// See also: ParseBigBytes.
//
// BigIBytes(82854982) -> 79MiB
// BigIBytes(82854982) -> 79 MiB
func BigIBytes(s *big.Int) string {
sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}
return humanateBigBytes(s, bigIECExp, sizes)
@ -134,19 +134,28 @@ func BigIBytes(s *big.Int) string {
//
// See also: BigBytes, BigIBytes.
//
// ParseBigBytes("42MB") -> 42000000, nil
// ParseBigBytes("42mib") -> 44040192, nil
// ParseBigBytes("42 MB") -> 42000000, nil
// ParseBigBytes("42 mib") -> 44040192, nil
func ParseBigBytes(s string) (*big.Int, 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++
}
num := s[:lastDigit]
if hasComma {
num = strings.Replace(num, ",", "", -1)
}
val := &big.Rat{}
_, err := fmt.Sscanf(s[:lastDigit], "%f", val)
_, err := fmt.Sscanf(num, "%f", val)
if err != nil {
return nil, err
}