Update Go dependencies

This commit is contained in:
Matthias Loibl 2022-06-22 16:25:58 +02:00
parent 09e1f13509
commit d3d7715750
No known key found for this signature in database
GPG key ID: 78A796CA74CA38BA
391 changed files with 73854 additions and 103071 deletions

1
vendor/github.com/alecthomas/template/go.mod generated vendored Normal file
View file

@ -0,0 +1 @@
module github.com/alecthomas/template

View file

@ -1,3 +1,5 @@
[![Go Reference](https://pkg.go.dev/badge/github.com/alecthomas/units.svg)](https://pkg.go.dev/github.com/alecthomas/units)
# Units - Helpful unit multipliers and functions for Go
The goal of this package is to have functionality similar to the [time](http://golang.org/pkg/time/) package.

View file

@ -27,6 +27,7 @@ var (
// ParseBase2Bytes supports both iB and B in base-2 multipliers. That is, KB
// and KiB are both 1024.
// However "kB", which is the correct SI spelling of 1000 Bytes, is rejected.
func ParseBase2Bytes(s string) (Base2Bytes, error) {
n, err := ParseUnit(s, bytesUnitMap)
if err != nil {
@ -39,9 +40,76 @@ func (b Base2Bytes) String() string {
return ToString(int64(b), 1024, "iB", "B")
}
var (
metricBytesUnitMap = MakeUnitMap("B", "B", 1000)
)
// MarshalText implement encoding.TextMarshaler to process json/yaml.
func (b Base2Bytes) MarshalText() ([]byte, error) {
return []byte(b.String()), nil
}
// UnmarshalText implement encoding.TextUnmarshaler to process json/yaml.
func (b *Base2Bytes) UnmarshalText(text []byte) error {
n, err := ParseBase2Bytes(string(text))
*b = n
return err
}
// Floor returns Base2Bytes with all but the largest unit zeroed out. So that e.g. 1GiB1MiB1KiB → 1GiB.
func (b Base2Bytes) Floor() Base2Bytes {
switch {
case b > Exbibyte:
return (b / Exbibyte) * Exbibyte
case b > Pebibyte:
return (b / Pebibyte) * Pebibyte
case b > Tebibyte:
return (b / Tebibyte) * Tebibyte
case b > Gibibyte:
return (b / Gibibyte) * Gibibyte
case b > Mebibyte:
return (b / Mebibyte) * Mebibyte
case b > Kibibyte:
return (b / Kibibyte) * Kibibyte
default:
return b
}
}
// Round returns Base2Bytes with all but the first n units zeroed out. So that e.g. 1GiB1MiB1KiB → 1GiB1MiB, if n is 2.
func (b Base2Bytes) Round(n int) Base2Bytes {
idx := 0
switch {
case b > Exbibyte:
idx = n
case b > Pebibyte:
idx = n + 1
case b > Tebibyte:
idx = n + 2
case b > Gibibyte:
idx = n + 3
case b > Mebibyte:
idx = n + 4
case b > Kibibyte:
idx = n + 5
}
switch idx {
case 1:
return b - b%Exbibyte
case 2:
return b - b%Pebibyte
case 3:
return b - b%Tebibyte
case 4:
return b - b%Gibibyte
case 5:
return b - b%Mebibyte
case 6:
return b - b%Kibibyte
default:
return b
}
}
var metricBytesUnitMap = MakeUnitMap("B", "B", 1000)
// MetricBytes are SI byte units (1000 bytes in a kilobyte).
type MetricBytes SI
@ -68,12 +136,70 @@ func ParseMetricBytes(s string) (MetricBytes, error) {
return MetricBytes(n), err
}
// TODO: represents 1000B as uppercase "KB", while SI standard requires "kB".
func (m MetricBytes) String() string {
return ToString(int64(m), 1000, "B", "B")
}
// Floor returns MetricBytes with all but the largest unit zeroed out. So that e.g. 1GB1MB1KB → 1GB.
func (b MetricBytes) Floor() MetricBytes {
switch {
case b > Exabyte:
return (b / Exabyte) * Exabyte
case b > Petabyte:
return (b / Petabyte) * Petabyte
case b > Terabyte:
return (b / Terabyte) * Terabyte
case b > Gigabyte:
return (b / Gigabyte) * Gigabyte
case b > Megabyte:
return (b / Megabyte) * Megabyte
case b > Kilobyte:
return (b / Kilobyte) * Kilobyte
default:
return b
}
}
// Round returns MetricBytes with all but the first n units zeroed out. So that e.g. 1GB1MB1KB → 1GB1MB, if n is 2.
func (b MetricBytes) Round(n int) MetricBytes {
idx := 0
switch {
case b > Exabyte:
idx = n
case b > Petabyte:
idx = n + 1
case b > Terabyte:
idx = n + 2
case b > Gigabyte:
idx = n + 3
case b > Megabyte:
idx = n + 4
case b > Kilobyte:
idx = n + 5
}
switch idx {
case 1:
return b - b%Exabyte
case 2:
return b - b%Petabyte
case 3:
return b - b%Terabyte
case 4:
return b - b%Gigabyte
case 5:
return b - b%Megabyte
case 6:
return b - b%Kilobyte
default:
return b
}
}
// ParseStrictBytes supports both iB and B suffixes for base 2 and metric,
// respectively. That is, KiB represents 1024 and KB represents 1000.
// respectively. That is, KiB represents 1024 and kB, KB represent 1000.
func ParseStrictBytes(s string) (int64, error) {
n, err := ParseUnit(s, bytesUnitMap)
if err != nil {

5
vendor/github.com/alecthomas/units/go.mod generated vendored Normal file
View file

@ -0,0 +1,5 @@
module github.com/alecthomas/units
go 1.15
require github.com/stretchr/testify v1.4.0

11
vendor/github.com/alecthomas/units/go.sum generated vendored Normal file
View file

@ -0,0 +1,11 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View file

@ -14,13 +14,37 @@ const (
)
func MakeUnitMap(suffix, shortSuffix string, scale int64) map[string]float64 {
return map[string]float64{
shortSuffix: 1,
"K" + suffix: float64(scale),
res := map[string]float64{
shortSuffix: 1,
// see below for "k" / "K"
"M" + suffix: float64(scale * scale),
"G" + suffix: float64(scale * scale * scale),
"T" + suffix: float64(scale * scale * scale * scale),
"P" + suffix: float64(scale * scale * scale * scale * scale),
"E" + suffix: float64(scale * scale * scale * scale * scale * scale),
}
// Standard SI prefixes use lowercase "k" for kilo = 1000.
// For compatibility, and to be fool-proof, we accept both "k" and "K" in metric mode.
//
// However, official binary prefixes are always capitalized - "KiB" -
// and we specifically never parse "kB" as 1024B because:
//
// (1) people pedantic enough to use lowercase according to SI unlikely to abuse "k" to mean 1024 :-)
//
// (2) Use of capital K for 1024 was an informal tradition predating IEC prefixes:
// "The binary meaning of the kilobyte for 1024 bytes typically uses the symbol KB, with an
// uppercase letter K."
// -- https://en.wikipedia.org/wiki/Kilobyte#Base_2_(1024_bytes)
// "Capitalization of the letter K became the de facto standard for binary notation, although this
// could not be extended to higher powers, and use of the lowercase k did persist.[13][14][15]"
// -- https://en.wikipedia.org/wiki/Binary_prefix#History
// See also the extensive https://en.wikipedia.org/wiki/Timeline_of_binary_prefixes.
if scale == 1024 {
res["K"+suffix] = float64(scale)
} else {
res["k"+suffix] = float64(scale)
res["K"+suffix] = float64(scale)
}
return res
}