From 6a4a30f5d146f2970c17fb93b0dd973a9c820bd2 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 17 Nov 2017 14:02:13 -0800 Subject: [PATCH] vendor: upgrade grpc-gateway to v1.3.0, dustin/go-humanize Signed-off-by: Gyu-Ho Lee --- .../github.com/dustin/go-humanize/bigbytes.go | 21 +++-- .../github.com/dustin/go-humanize/bytes.go | 21 +++-- .../github.com/dustin/go-humanize/comma.go | 9 ++- .../github.com/dustin/go-humanize/commaf.go | 40 ++++++++++ .../github.com/dustin/go-humanize/humanize.go | 4 +- .../github.com/dustin/go-humanize/number.go | 2 +- .../github.com/dustin/go-humanize/si.go | 19 +++-- .../github.com/dustin/go-humanize/times.go | 76 +++++++++++++------ glide.lock | 6 +- glide.yaml | 4 +- 10 files changed, 148 insertions(+), 54 deletions(-) create mode 100644 cmd/vendor/github.com/dustin/go-humanize/commaf.go diff --git a/cmd/vendor/github.com/dustin/go-humanize/bigbytes.go b/cmd/vendor/github.com/dustin/go-humanize/bigbytes.go index 67ea5c823..1a2bf6172 100644 --- a/cmd/vendor/github.com/dustin/go-humanize/bigbytes.go +++ b/cmd/vendor/github.com/dustin/go-humanize/bigbytes.go @@ -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 } diff --git a/cmd/vendor/github.com/dustin/go-humanize/bytes.go b/cmd/vendor/github.com/dustin/go-humanize/bytes.go index dacbb9c1e..0b498f488 100644 --- a/cmd/vendor/github.com/dustin/go-humanize/bytes.go +++ b/cmd/vendor/github.com/dustin/go-humanize/bytes.go @@ -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 } diff --git a/cmd/vendor/github.com/dustin/go-humanize/comma.go b/cmd/vendor/github.com/dustin/go-humanize/comma.go index b65ea6fa7..13611aaab 100644 --- a/cmd/vendor/github.com/dustin/go-humanize/comma.go +++ b/cmd/vendor/github.com/dustin/go-humanize/comma.go @@ -2,6 +2,7 @@ package humanize import ( "bytes" + "math" "math/big" "strconv" "strings" @@ -13,6 +14,12 @@ import ( // e.g. Comma(834142) -> 834,142 func Comma(v int64) string { sign := "" + + // Min int64 can't be negated to a usable value, so it has to be special cased. + if v == math.MinInt64 { + return "-9,223,372,036,854,775,808" + } + if v < 0 { sign = "-" v = 0 - v @@ -39,7 +46,7 @@ func Comma(v int64) string { // Commaf produces a string form of the given number in base 10 with // commas after every three orders of magnitude. // -// e.g. Comma(834142.32) -> 834,142.32 +// e.g. Commaf(834142.32) -> 834,142.32 func Commaf(v float64) string { buf := &bytes.Buffer{} if v < 0 { diff --git a/cmd/vendor/github.com/dustin/go-humanize/commaf.go b/cmd/vendor/github.com/dustin/go-humanize/commaf.go new file mode 100644 index 000000000..620690dec --- /dev/null +++ b/cmd/vendor/github.com/dustin/go-humanize/commaf.go @@ -0,0 +1,40 @@ +// +build go1.6 + +package humanize + +import ( + "bytes" + "math/big" + "strings" +) + +// BigCommaf produces a string form of the given big.Float in base 10 +// with commas after every three orders of magnitude. +func BigCommaf(v *big.Float) string { + buf := &bytes.Buffer{} + if v.Sign() < 0 { + buf.Write([]byte{'-'}) + v.Abs(v) + } + + comma := []byte{','} + + parts := strings.Split(v.Text('f', -1), ".") + pos := 0 + if len(parts[0])%3 != 0 { + pos += len(parts[0]) % 3 + buf.WriteString(parts[0][:pos]) + buf.Write(comma) + } + for ; pos < len(parts[0]); pos += 3 { + buf.WriteString(parts[0][pos : pos+3]) + buf.Write(comma) + } + buf.Truncate(buf.Len() - 1) + + if len(parts) > 1 { + buf.Write([]byte{'.'}) + buf.WriteString(parts[1]) + } + return buf.String() +} diff --git a/cmd/vendor/github.com/dustin/go-humanize/humanize.go b/cmd/vendor/github.com/dustin/go-humanize/humanize.go index a69540a06..a2c2da31e 100644 --- a/cmd/vendor/github.com/dustin/go-humanize/humanize.go +++ b/cmd/vendor/github.com/dustin/go-humanize/humanize.go @@ -2,7 +2,7 @@ Package humanize converts boring ugly numbers to human-friendly strings and back. Durations can be turned into strings such as "3 days ago", numbers -representing sizes like 82854982 into useful strings like, "83MB" or -"79MiB" (whichever you prefer). +representing sizes like 82854982 into useful strings like, "83 MB" or +"79 MiB" (whichever you prefer). */ package humanize diff --git a/cmd/vendor/github.com/dustin/go-humanize/number.go b/cmd/vendor/github.com/dustin/go-humanize/number.go index 32141348c..dec618659 100644 --- a/cmd/vendor/github.com/dustin/go-humanize/number.go +++ b/cmd/vendor/github.com/dustin/go-humanize/number.go @@ -160,7 +160,7 @@ func FormatFloat(format string, n float64) string { intf, fracf := math.Modf(n + renderFloatPrecisionRounders[precision]) // generate integer part string - intStr := strconv.Itoa(int(intf)) + intStr := strconv.FormatInt(int64(intf), 10) // add thousand separator if required if len(thousandStr) > 0 { diff --git a/cmd/vendor/github.com/dustin/go-humanize/si.go b/cmd/vendor/github.com/dustin/go-humanize/si.go index fe86fe556..b24e48169 100644 --- a/cmd/vendor/github.com/dustin/go-humanize/si.go +++ b/cmd/vendor/github.com/dustin/go-humanize/si.go @@ -41,7 +41,7 @@ func revfmap(in map[float64]string) map[string]float64 { var riParseRegex *regexp.Regexp func init() { - ri := `^([0-9.]+)\s?([` + ri := `^([\-0-9.]+)\s?([` for _, v := range siPrefixTable { ri += v } @@ -61,18 +61,21 @@ func ComputeSI(input float64) (float64, string) { if input == 0 { return 0, "" } - exponent := math.Floor(logn(input, 10)) + mag := math.Abs(input) + exponent := math.Floor(logn(mag, 10)) exponent = math.Floor(exponent/3) * 3 - value := input / math.Pow(10, exponent) + value := mag / math.Pow(10, exponent) // Handle special case where value is exactly 1000.0 - // Should return 1M instead of 1000k + // Should return 1 M instead of 1000 k if value == 1000.0 { exponent += 3 - value = input / math.Pow(10, exponent) + value = mag / math.Pow(10, exponent) } + value = math.Copysign(value, input) + prefix := siPrefixTable[exponent] return value, prefix } @@ -83,8 +86,8 @@ func ComputeSI(input float64) (float64, string) { // // See also: ComputeSI, ParseSI. // -// e.g. SI(1000000, B) -> 1MB -// e.g. SI(2.2345e-12, "F") -> 2.2345pF +// e.g. SI(1000000, "B") -> 1 MB +// e.g. SI(2.2345e-12, "F") -> 2.2345 pF func SI(input float64, unit string) string { value, prefix := ComputeSI(input) return Ftoa(value) + " " + prefix + unit @@ -96,7 +99,7 @@ var errInvalid = errors.New("invalid input") // // See also: SI, ComputeSI. // -// e.g. ParseSI(2.2345pF) -> (2.2345e-12, "F", nil) +// e.g. ParseSI("2.2345 pF") -> (2.2345e-12, "F", nil) func ParseSI(input string) (float64, string, error) { found := riParseRegex.FindStringSubmatch(input) if len(found) != 4 { diff --git a/cmd/vendor/github.com/dustin/go-humanize/times.go b/cmd/vendor/github.com/dustin/go-humanize/times.go index 592ebe1d6..dd3fbf5ef 100644 --- a/cmd/vendor/github.com/dustin/go-humanize/times.go +++ b/cmd/vendor/github.com/dustin/go-humanize/times.go @@ -9,9 +9,7 @@ import ( // Seconds-based time units const ( - Minute = 60 - Hour = 60 * Minute - Day = 24 * Hour + Day = 24 * time.Hour Week = 7 * Day Month = 30 * Day Year = 12 * Month @@ -25,18 +23,35 @@ func Time(then time.Time) string { return RelTime(then, time.Now(), "ago", "from now") } -var magnitudes = []struct { - d int64 - format string - divby int64 -}{ - {1, "now", 1}, - {2, "1 second %s", 1}, - {Minute, "%d seconds %s", 1}, - {2 * Minute, "1 minute %s", 1}, - {Hour, "%d minutes %s", Minute}, - {2 * Hour, "1 hour %s", 1}, - {Day, "%d hours %s", Hour}, +// A RelTimeMagnitude struct contains a relative time point at which +// the relative format of time will switch to a new format string. A +// slice of these in ascending order by their "D" field is passed to +// CustomRelTime to format durations. +// +// The Format field is a string that may contain a "%s" which will be +// replaced with the appropriate signed label (e.g. "ago" or "from +// now") and a "%d" that will be replaced by the quantity. +// +// The DivBy field is the amount of time the time difference must be +// divided by in order to display correctly. +// +// e.g. if D is 2*time.Minute and you want to display "%d minutes %s" +// DivBy should be time.Minute so whatever the duration is will be +// expressed in minutes. +type RelTimeMagnitude struct { + D time.Duration + Format string + DivBy time.Duration +} + +var defaultMagnitudes = []RelTimeMagnitude{ + {time.Second, "now", time.Second}, + {2 * time.Second, "1 second %s", 1}, + {time.Minute, "%d seconds %s", time.Second}, + {2 * time.Minute, "1 minute %s", 1}, + {time.Hour, "%d minutes %s", time.Minute}, + {2 * time.Hour, "1 hour %s", 1}, + {Day, "%d hours %s", time.Hour}, {2 * Day, "1 day %s", 1}, {Week, "%d days %s", Day}, {2 * Week, "1 week %s", 1}, @@ -57,35 +72,46 @@ var magnitudes = []struct { // // RelTime(timeInPast, timeInFuture, "earlier", "later") -> "3 weeks earlier" func RelTime(a, b time.Time, albl, blbl string) string { - lbl := albl - diff := b.Unix() - a.Unix() + return CustomRelTime(a, b, albl, blbl, defaultMagnitudes) +} - after := a.After(b) - if after { +// CustomRelTime formats a time into a relative string. +// +// It takes two times two labels and a table of relative time formats. +// In addition to the generic time delta string (e.g. 5 minutes), the +// labels are used applied so that the label corresponding to the +// smaller time is applied. +func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string { + lbl := albl + diff := b.Sub(a) + + if a.After(b) { lbl = blbl - diff = a.Unix() - b.Unix() + diff = a.Sub(b) } n := sort.Search(len(magnitudes), func(i int) bool { - return magnitudes[i].d > diff + return magnitudes[i].D > diff }) + if n >= len(magnitudes) { + n = len(magnitudes) - 1 + } mag := magnitudes[n] args := []interface{}{} escaped := false - for _, ch := range mag.format { + for _, ch := range mag.Format { if escaped { switch ch { - case '%': case 's': args = append(args, lbl) case 'd': - args = append(args, diff/mag.divby) + args = append(args, diff/mag.DivBy) } escaped = false } else { escaped = ch == '%' } } - return fmt.Sprintf(mag.format, args...) + return fmt.Sprintf(mag.Format, args...) } diff --git a/glide.lock b/glide.lock index 6e94f4cbc..424d02d5c 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 2244aad388c98d02a53083ff704bc2f5da72978ef7330ef588ced88822b70e23 -updated: 2017-11-16T10:30:18.004311-08:00 +hash: 8136b7373396e6f72a1f99838d706292c688ccb94bb1bddee7124babde335e31 +updated: 2017-11-17T14:01:41.761462-08:00 imports: - name: github.com/beorn7/perks version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 @@ -31,7 +31,7 @@ imports: - name: github.com/dgrijalva/jwt-go version: d2709f9f1f31ebcda9651b03077758c1f3a0018c - name: github.com/dustin/go-humanize - version: 8929fe90cee4b2cb9deb468b51fb34eba64d1bf0 + version: bb3d318650d48840a39aa21a027c6630e198e626 - name: github.com/ghodss/yaml version: 0ca9ea5df5451ffdf184b4428c902747c2c11cd7 - name: github.com/gogo/protobuf diff --git a/glide.yaml b/glide.yaml index 2820a450c..7a1d89015 100644 --- a/glide.yaml +++ b/glide.yaml @@ -23,7 +23,7 @@ import: - package: github.com/cpuguy83/go-md2man version: 23709d0847197db6021a51fdb193e66e9222d4e7 - package: github.com/dustin/go-humanize - version: 8929fe90cee4b2cb9deb468b51fb34eba64d1bf0 + version: bb3d318650d48840a39aa21a027c6630e198e626 - package: github.com/ghodss/yaml version: v1.0.0 - package: github.com/gogo/protobuf @@ -44,7 +44,7 @@ import: - package: github.com/google/btree version: 925471ac9e2131377a91e1595defec898166fe49 - package: github.com/grpc-ecosystem/grpc-gateway - version: v1.3 + version: v1.3.0 subpackages: - runtime - runtime/internal