diff options
| author | 2025-05-10 14:27:25 +0000 | |
|---|---|---|
| committer | 2025-05-10 14:27:25 +0000 | |
| commit | d2f13e7564059cb4be90650b570b93e4acc964a9 (patch) | |
| tree | ef47f253925ae524ad9da242345ac4afadcaa970 /vendor/github.com | |
| parent | [chore] Poke at `bundle_licenses.sh` a bit to make the output slightly easier... (diff) | |
| download | gotosocial-d2f13e7564059cb4be90650b570b93e4acc964a9.tar.xz | |
[chore] update direct Go dependencies (#4162)
- update gruf/go-stroage v0.2.0 -> v0.2.1
- update KimMachineGun/automemlimit v0.7.1 -> v0.7.2
- update miekg/dns v1.1.65 -> v1.1.66
- update ncruces/go-sqlite3 v0.25.1 -> v0.25.2
- update spf13/cast v1.7.1 -> v1.8.0
- update tdewolff/minify/v2 v2.23.1 -> v2.23.5
- update x/crypto v0.37.0 -> v0.38.0
- update x/image v0.26.0 -> v0.27.0
- update x/net v0.39.0 -> v0.40.0
- update x/oauth2 v0.29.0 -> v0.30.0
- update x/sys v0.32.0 -> v0.33.0
- update x/text v0.24.0 -> v0.25.0
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4162
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/github.com')
18 files changed, 300 insertions, 225 deletions
diff --git a/vendor/github.com/KimMachineGun/automemlimit/memlimit/cgroups.go b/vendor/github.com/KimMachineGun/automemlimit/memlimit/cgroups.go index 73a57c3eb..69d1771f0 100644 --- a/vendor/github.com/KimMachineGun/automemlimit/memlimit/cgroups.go +++ b/vendor/github.com/KimMachineGun/automemlimit/memlimit/cgroups.go @@ -276,11 +276,9 @@ func parseMountInfoLine(line string) (mountInfo, error) { fields1 = append(fields1, "") } - fields2 := strings.Split(fieldss[1], " ") + fields2 := strings.SplitN(fieldss[1], " ", 3) if len(fields2) < 3 { return mountInfo{}, fmt.Errorf("not enough fields after separator: %v", fields2) - } else if len(fields2) > 3 { - return mountInfo{}, fmt.Errorf("too many fields after separator: %v", fields2) } return mountInfo{ diff --git a/vendor/github.com/miekg/dns/README.md b/vendor/github.com/miekg/dns/README.md index 0e42858ae..54471f5c2 100644 --- a/vendor/github.com/miekg/dns/README.md +++ b/vendor/github.com/miekg/dns/README.md @@ -185,6 +185,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository. * 7871 - EDNS0 Client Subnet * 7873 - Domain Name System (DNS) Cookies * 8080 - EdDSA for DNSSEC +* 8490 - DNS Stateful Operations * 8499 - DNS Terminology * 8659 - DNS Certification Authority Authorization (CAA) Resource Record * 8777 - DNS Reverse IP Automatic Multicast Tunneling (AMT) Discovery diff --git a/vendor/github.com/miekg/dns/msg.go b/vendor/github.com/miekg/dns/msg.go index 5fa7f9e83..d87b5323b 100644 --- a/vendor/github.com/miekg/dns/msg.go +++ b/vendor/github.com/miekg/dns/msg.go @@ -136,18 +136,19 @@ var OpcodeToString = map[int]string{ // RcodeToString maps Rcodes to strings. var RcodeToString = map[int]string{ - RcodeSuccess: "NOERROR", - RcodeFormatError: "FORMERR", - RcodeServerFailure: "SERVFAIL", - RcodeNameError: "NXDOMAIN", - RcodeNotImplemented: "NOTIMP", - RcodeRefused: "REFUSED", - RcodeYXDomain: "YXDOMAIN", // See RFC 2136 - RcodeYXRrset: "YXRRSET", - RcodeNXRrset: "NXRRSET", - RcodeNotAuth: "NOTAUTH", - RcodeNotZone: "NOTZONE", - RcodeBadSig: "BADSIG", // Also known as RcodeBadVers, see RFC 6891 + RcodeSuccess: "NOERROR", + RcodeFormatError: "FORMERR", + RcodeServerFailure: "SERVFAIL", + RcodeNameError: "NXDOMAIN", + RcodeNotImplemented: "NOTIMP", + RcodeRefused: "REFUSED", + RcodeYXDomain: "YXDOMAIN", // See RFC 2136 + RcodeYXRrset: "YXRRSET", + RcodeNXRrset: "NXRRSET", + RcodeNotAuth: "NOTAUTH", + RcodeNotZone: "NOTZONE", + RcodeStatefulTypeNotImplemented: "DSOTYPENI", + RcodeBadSig: "BADSIG", // Also known as RcodeBadVers, see RFC 6891 // RcodeBadVers: "BADVERS", RcodeBadKey: "BADKEY", RcodeBadTime: "BADTIME", @@ -874,7 +875,6 @@ func (dns *Msg) unpack(dh Header, msg []byte, off int) (err error) { // // println("dns: extra bytes in dns packet", off, "<", len(msg)) // } return err - } // Unpack unpacks a binary message to a Msg structure. diff --git a/vendor/github.com/miekg/dns/reverse.go b/vendor/github.com/miekg/dns/reverse.go index 28151af83..6f5b3ea70 100644 --- a/vendor/github.com/miekg/dns/reverse.go +++ b/vendor/github.com/miekg/dns/reverse.go @@ -23,9 +23,12 @@ var StringToAlgorithm = reverseInt8(AlgorithmToString) // StringToHash is a map of names to hash IDs. var StringToHash = reverseInt8(HashToString) -// StringToCertType is the reverseof CertTypeToString. +// StringToCertType is the reverse of CertTypeToString. var StringToCertType = reverseInt16(CertTypeToString) +// StringToStatefulType is the reverse of StatefulTypeToString. +var StringToStatefulType = reverseInt16(StatefulTypeToString) + // Reverse a map func reverseInt8(m map[uint8]string) map[string]uint8 { n := make(map[string]uint8, len(m)) diff --git a/vendor/github.com/miekg/dns/scan.go b/vendor/github.com/miekg/dns/scan.go index fa8a332ed..31957b2ea 100644 --- a/vendor/github.com/miekg/dns/scan.go +++ b/vendor/github.com/miekg/dns/scan.go @@ -1318,6 +1318,13 @@ func toAbsoluteName(name, origin string) (absolute string, ok bool) { return origin, true } + // this can happen when we have a comment after a RR that has a domain, '... MX 20 ; this is wrong'. + // technically a newline can be in a domain name, but this is clearly an error and the newline only shows + // because of the scanning and the comment. + if name == "\n" { + return "", false + } + // require a valid domain name _, ok = IsDomainName(name) if !ok || name == "" { diff --git a/vendor/github.com/miekg/dns/types.go b/vendor/github.com/miekg/dns/types.go index e39cf2fec..f5067cd43 100644 --- a/vendor/github.com/miekg/dns/types.go +++ b/vendor/github.com/miekg/dns/types.go @@ -126,33 +126,35 @@ const ( ClassANY = 255 // Message Response Codes, see https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml - RcodeSuccess = 0 // NoError - No Error [DNS] - RcodeFormatError = 1 // FormErr - Format Error [DNS] - RcodeServerFailure = 2 // ServFail - Server Failure [DNS] - RcodeNameError = 3 // NXDomain - Non-Existent Domain [DNS] - RcodeNotImplemented = 4 // NotImp - Not Implemented [DNS] - RcodeRefused = 5 // Refused - Query Refused [DNS] - RcodeYXDomain = 6 // YXDomain - Name Exists when it should not [DNS Update] - RcodeYXRrset = 7 // YXRRSet - RR Set Exists when it should not [DNS Update] - RcodeNXRrset = 8 // NXRRSet - RR Set that should exist does not [DNS Update] - RcodeNotAuth = 9 // NotAuth - Server Not Authoritative for zone [DNS Update] - RcodeNotZone = 10 // NotZone - Name not contained in zone [DNS Update/TSIG] - RcodeBadSig = 16 // BADSIG - TSIG Signature Failure [TSIG] https://www.rfc-editor.org/rfc/rfc6895.html#section-2.3 - RcodeBadVers = 16 // BADVERS - Bad OPT Version [EDNS0] https://www.rfc-editor.org/rfc/rfc6895.html#section-2.3 - RcodeBadKey = 17 // BADKEY - Key not recognized [TSIG] - RcodeBadTime = 18 // BADTIME - Signature out of time window [TSIG] - RcodeBadMode = 19 // BADMODE - Bad TKEY Mode [TKEY] - RcodeBadName = 20 // BADNAME - Duplicate key name [TKEY] - RcodeBadAlg = 21 // BADALG - Algorithm not supported [TKEY] - RcodeBadTrunc = 22 // BADTRUNC - Bad Truncation [TSIG] - RcodeBadCookie = 23 // BADCOOKIE - Bad/missing Server Cookie [DNS Cookies] + RcodeSuccess = 0 // NoError - No Error [DNS] + RcodeFormatError = 1 // FormErr - Format Error [DNS] + RcodeServerFailure = 2 // ServFail - Server Failure [DNS] + RcodeNameError = 3 // NXDomain - Non-Existent Domain [DNS] + RcodeNotImplemented = 4 // NotImp - Not Implemented [DNS] + RcodeRefused = 5 // Refused - Query Refused [DNS] + RcodeYXDomain = 6 // YXDomain - Name Exists when it should not [DNS Update] + RcodeYXRrset = 7 // YXRRSet - RR Set Exists when it should not [DNS Update] + RcodeNXRrset = 8 // NXRRSet - RR Set that should exist does not [DNS Update] + RcodeNotAuth = 9 // NotAuth - Server Not Authoritative for zone [DNS Update] + RcodeNotZone = 10 // NotZone - Name not contained in zone [DNS Update/TSIG] + RcodeStatefulTypeNotImplemented = 11 // DSOTypeNI - DSO-TYPE not implemented [DNS Stateful Operations] https://www.rfc-editor.org/rfc/rfc8490.html#section-10.2 + RcodeBadSig = 16 // BADSIG - TSIG Signature Failure [TSIG] https://www.rfc-editor.org/rfc/rfc6895.html#section-2.3 + RcodeBadVers = 16 // BADVERS - Bad OPT Version [EDNS0] https://www.rfc-editor.org/rfc/rfc6895.html#section-2.3 + RcodeBadKey = 17 // BADKEY - Key not recognized [TSIG] + RcodeBadTime = 18 // BADTIME - Signature out of time window [TSIG] + RcodeBadMode = 19 // BADMODE - Bad TKEY Mode [TKEY] + RcodeBadName = 20 // BADNAME - Duplicate key name [TKEY] + RcodeBadAlg = 21 // BADALG - Algorithm not supported [TKEY] + RcodeBadTrunc = 22 // BADTRUNC - Bad Truncation [TSIG] + RcodeBadCookie = 23 // BADCOOKIE - Bad/missing Server Cookie [DNS Cookies] // Message Opcodes. There is no 3. - OpcodeQuery = 0 - OpcodeIQuery = 1 - OpcodeStatus = 2 - OpcodeNotify = 4 - OpcodeUpdate = 5 + OpcodeQuery = 0 + OpcodeIQuery = 1 + OpcodeStatus = 2 + OpcodeNotify = 4 + OpcodeUpdate = 5 + OpcodeStateful = 6 ) // Used in ZONEMD https://tools.ietf.org/html/rfc8976 @@ -179,6 +181,19 @@ const ( AMTRELAYHost = IPSECGatewayHost ) +// Stateful types as defined in RFC 8490. +const ( + StatefulTypeKeepAlive uint16 = iota + 1 + StatefulTypeRetryDelay + StatefulTypeEncryptionPadding +) + +var StatefulTypeToString = map[uint16]string{ + StatefulTypeKeepAlive: "KeepAlive", + StatefulTypeRetryDelay: "RetryDelay", + StatefulTypeEncryptionPadding: "EncryptionPadding", +} + // Header is the wire format for the DNS packet header. type Header struct { Id uint16 @@ -886,7 +901,7 @@ func (rr *LOC) String() string { lon = lon % LOC_HOURS s += fmt.Sprintf("%02d %02d %0.3f %s ", h, m, float64(lon)/1000, ew) - var alt = float64(rr.Altitude) / 100 + alt := float64(rr.Altitude) / 100 alt -= LOC_ALTITUDEBASE if rr.Altitude%100 != 0 { s += fmt.Sprintf("%.2fm ", alt) diff --git a/vendor/github.com/miekg/dns/version.go b/vendor/github.com/miekg/dns/version.go index 73e34edc3..936dc2124 100644 --- a/vendor/github.com/miekg/dns/version.go +++ b/vendor/github.com/miekg/dns/version.go @@ -3,7 +3,7 @@ package dns import "fmt" // Version is current version of this library. -var Version = v{1, 1, 65} +var Version = v{1, 1, 66} // v holds the version of this library. type v struct { diff --git a/vendor/github.com/miekg/dns/xfr.go b/vendor/github.com/miekg/dns/xfr.go index 5cfbb516a..97a642471 100644 --- a/vendor/github.com/miekg/dns/xfr.go +++ b/vendor/github.com/miekg/dns/xfr.go @@ -251,10 +251,13 @@ func (t *Transfer) ReadMsg() (*Msg, error) { if err := m.Unpack(p); err != nil { return nil, err } - if ts, tp := m.IsTsig(), t.tsigProvider(); ts != nil && tp != nil { + + if tp := t.tsigProvider(); tp != nil { // Need to work on the original message p, as that was used to calculate the tsig. err = TsigVerifyWithProvider(p, tp, t.tsigRequestMAC, t.tsigTimersOnly) - t.tsigRequestMAC = ts.MAC + if ts := m.IsTsig(); ts != nil { + t.tsigRequestMAC = ts.MAC + } } return m, err } diff --git a/vendor/github.com/ncruces/go-sqlite3/embed/README.md b/vendor/github.com/ncruces/go-sqlite3/embed/README.md index 765c4b685..1a2d575bb 100644 --- a/vendor/github.com/ncruces/go-sqlite3/embed/README.md +++ b/vendor/github.com/ncruces/go-sqlite3/embed/README.md @@ -1,6 +1,6 @@ # Embeddable Wasm build of SQLite -This folder includes an embeddable Wasm build of SQLite 3.49.1 for use with +This folder includes an embeddable Wasm build of SQLite 3.49.2 for use with [`github.com/ncruces/go-sqlite3`](https://pkg.go.dev/github.com/ncruces/go-sqlite3). The following optional features are compiled in: diff --git a/vendor/github.com/ncruces/go-sqlite3/embed/sqlite3.wasm b/vendor/github.com/ncruces/go-sqlite3/embed/sqlite3.wasm Binary files differindex 88ebe9932..44f667926 100644 --- a/vendor/github.com/ncruces/go-sqlite3/embed/sqlite3.wasm +++ b/vendor/github.com/ncruces/go-sqlite3/embed/sqlite3.wasm diff --git a/vendor/github.com/spf13/cast/.editorconfig b/vendor/github.com/spf13/cast/.editorconfig new file mode 100644 index 000000000..a85749f19 --- /dev/null +++ b/vendor/github.com/spf13/cast/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.go] +indent_style = tab + +[{*.yml,*.yaml}] +indent_size = 2 diff --git a/vendor/github.com/spf13/cast/.golangci.yaml b/vendor/github.com/spf13/cast/.golangci.yaml new file mode 100644 index 000000000..e00fd47aa --- /dev/null +++ b/vendor/github.com/spf13/cast/.golangci.yaml @@ -0,0 +1,39 @@ +version: "2" + +run: + timeout: 10m + +linters: + enable: + - errcheck + - govet + - ineffassign + - misspell + - nolintlint + # - revive + - unused + + disable: + - staticcheck + + settings: + misspell: + locale: US + nolintlint: + allow-unused: false # report any unused nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped + +formatters: + enable: + - gci + - gofmt + # - gofumpt + - goimports + # - golines + + settings: + gci: + sections: + - standard + - default + - localmodule diff --git a/vendor/github.com/spf13/cast/README.md b/vendor/github.com/spf13/cast/README.md index 1be666a45..c58eccb3f 100644 --- a/vendor/github.com/spf13/cast/README.md +++ b/vendor/github.com/spf13/cast/README.md @@ -1,9 +1,9 @@ # cast -[](https://github.com/spf13/cast/actions/workflows/test.yaml) -[](https://pkg.go.dev/mod/github.com/spf13/cast) - -[](https://goreportcard.com/report/github.com/spf13/cast) +[](https://github.com/spf13/cast/actions/workflows/ci.yaml) +[](https://pkg.go.dev/mod/github.com/spf13/cast) + +[](https://deps.dev/go/github.com%252Fspf13%252Fcast) Easy and safe casting from one type to another in Go @@ -73,3 +73,7 @@ the code for a complete set. var eight interface{} = 8 cast.ToInt(eight) // 8 cast.ToInt(nil) // 0 + +## License + +The project is licensed under the [MIT License](LICENSE). diff --git a/vendor/github.com/spf13/cast/cast.go b/vendor/github.com/spf13/cast/cast.go index 0cfe9418d..386ba80a9 100644 --- a/vendor/github.com/spf13/cast/cast.go +++ b/vendor/github.com/spf13/cast/cast.go @@ -169,6 +169,24 @@ func ToIntSlice(i interface{}) []int { return v } +// ToInt64Slice casts an interface to a []int64 type. +func ToInt64Slice(i interface{}) []int64 { + v, _ := ToInt64SliceE(i) + return v +} + +// ToUintSlice casts an interface to a []uint type. +func ToUintSlice(i interface{}) []uint { + v, _ := ToUintSliceE(i) + return v +} + +// ToFloat64Slice casts an interface to a []float64 type. +func ToFloat64Slice(i interface{}) []float64 { + v, _ := ToFloat64SliceE(i) + return v +} + // ToDurationSlice casts an interface to a []time.Duration type. func ToDurationSlice(i interface{}) []time.Duration { v, _ := ToDurationSliceE(i) diff --git a/vendor/github.com/spf13/cast/caste.go b/vendor/github.com/spf13/cast/caste.go index 4181a2e75..4d4ca8db1 100644 --- a/vendor/github.com/spf13/cast/caste.go +++ b/vendor/github.com/spf13/cast/caste.go @@ -615,9 +615,6 @@ func ToUint64E(i interface{}) (uint64, error) { case string: v, err := strconv.ParseUint(trimZeroDecimal(s), 0, 0) if err == nil { - if v < 0 { - return 0, errNegativeNotAllowed - } return v, nil } return 0, fmt.Errorf("unable to cast %#v of type %T to uint64", i, i) @@ -1000,36 +997,57 @@ func ToStringE(i interface{}) (string, error) { } } -// ToStringMapStringE casts an interface to a map[string]string type. -func ToStringMapStringE(i interface{}) (map[string]string, error) { - m := map[string]string{} +func toMapE[K comparable, V any](i any, keyFn func(any) K, valFn func(any) V) (map[K]V, error) { + m := map[K]V{} + + if i == nil { + return m, fmt.Errorf("unable to cast %#v of type %T to %T", i, i, m) + } switch v := i.(type) { - case map[string]string: + case map[K]V: return v, nil - case map[string]interface{}: + + case map[K]any: for k, val := range v { - m[ToString(k)] = ToString(val) + m[k] = valFn(val) } + return m, nil - case map[interface{}]string: + + case map[any]V: for k, val := range v { - m[ToString(k)] = ToString(val) + m[keyFn(k)] = val } + return m, nil - case map[interface{}]interface{}: + + case map[any]any: for k, val := range v { - m[ToString(k)] = ToString(val) + m[keyFn(k)] = valFn(val) } + return m, nil + case string: err := jsonStringToObject(v, &m) + return m, err + default: - return m, fmt.Errorf("unable to cast %#v of type %T to map[string]string", i, i) + return m, fmt.Errorf("unable to cast %#v of type %T to %T", i, i, m) } } +func toStringMapE[T any](i any, fn func(any) T) (map[string]T, error) { + return toMapE(i, ToString, fn) +} + +// ToStringMapStringE casts an interface to a map[string]string type. +func ToStringMapStringE(i any) (map[string]string, error) { + return toStringMapE(i, ToString) +} + // ToStringMapStringSliceE casts an interface to a map[string][]string type. func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) { m := map[string][]string{} @@ -1096,130 +1114,83 @@ func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) { // ToStringMapBoolE casts an interface to a map[string]bool type. func ToStringMapBoolE(i interface{}) (map[string]bool, error) { - m := map[string]bool{} - - switch v := i.(type) { - case map[interface{}]interface{}: - for k, val := range v { - m[ToString(k)] = ToBool(val) - } - return m, nil - case map[string]interface{}: - for k, val := range v { - m[ToString(k)] = ToBool(val) - } - return m, nil - case map[string]bool: - return v, nil - case string: - err := jsonStringToObject(v, &m) - return m, err - default: - return m, fmt.Errorf("unable to cast %#v of type %T to map[string]bool", i, i) - } + return toStringMapE(i, ToBool) } // ToStringMapE casts an interface to a map[string]interface{} type. func ToStringMapE(i interface{}) (map[string]interface{}, error) { - m := map[string]interface{}{} + fn := func(i any) any { return i } - switch v := i.(type) { - case map[interface{}]interface{}: - for k, val := range v { - m[ToString(k)] = val - } - return m, nil - case map[string]interface{}: - return v, nil - case string: - err := jsonStringToObject(v, &m) - return m, err - default: - return m, fmt.Errorf("unable to cast %#v of type %T to map[string]interface{}", i, i) - } + return toStringMapE(i, fn) } -// ToStringMapIntE casts an interface to a map[string]int{} type. -func ToStringMapIntE(i interface{}) (map[string]int, error) { - m := map[string]int{} +func toStringMapIntE[T int | int64](i any, fn func(any) T, fnE func(any) (T, error)) (map[string]T, error) { + m := map[string]T{} + if i == nil { - return m, fmt.Errorf("unable to cast %#v of type %T to map[string]int", i, i) + return m, fmt.Errorf("unable to cast %#v of type %T to %T", i, i, m) } switch v := i.(type) { - case map[interface{}]interface{}: - for k, val := range v { - m[ToString(k)] = ToInt(val) - } - return m, nil - case map[string]interface{}: - for k, val := range v { - m[k] = ToInt(val) - } - return m, nil - case map[string]int: + case map[string]T: return v, nil - case string: - err := jsonStringToObject(v, &m) - return m, err - } - if reflect.TypeOf(i).Kind() != reflect.Map { - return m, fmt.Errorf("unable to cast %#v of type %T to map[string]int", i, i) - } - - mVal := reflect.ValueOf(m) - v := reflect.ValueOf(i) - for _, keyVal := range v.MapKeys() { - val, err := ToIntE(v.MapIndex(keyVal).Interface()) - if err != nil { - return m, fmt.Errorf("unable to cast %#v of type %T to map[string]int", i, i) + case map[string]any: + for k, val := range v { + m[k] = fn(val) } - mVal.SetMapIndex(keyVal, reflect.ValueOf(val)) - } - return m, nil -} -// ToStringMapInt64E casts an interface to a map[string]int64{} type. -func ToStringMapInt64E(i interface{}) (map[string]int64, error) { - m := map[string]int64{} - if i == nil { - return m, fmt.Errorf("unable to cast %#v of type %T to map[string]int64", i, i) - } + return m, nil - switch v := i.(type) { - case map[interface{}]interface{}: + case map[any]T: for k, val := range v { - m[ToString(k)] = ToInt64(val) + m[ToString(k)] = val } + return m, nil - case map[string]interface{}: + + case map[any]any: for k, val := range v { - m[k] = ToInt64(val) + m[ToString(k)] = fn(val) } + return m, nil - case map[string]int64: - return v, nil + case string: err := jsonStringToObject(v, &m) + return m, err } if reflect.TypeOf(i).Kind() != reflect.Map { - return m, fmt.Errorf("unable to cast %#v of type %T to map[string]int64", i, i) + return m, fmt.Errorf("unable to cast %#v of type %T to %T", i, i, m) } + mVal := reflect.ValueOf(m) v := reflect.ValueOf(i) + for _, keyVal := range v.MapKeys() { - val, err := ToInt64E(v.MapIndex(keyVal).Interface()) + val, err := fnE(v.MapIndex(keyVal).Interface()) if err != nil { - return m, fmt.Errorf("unable to cast %#v of type %T to map[string]int64", i, i) + return m, fmt.Errorf("unable to cast %#v of type %T to %T", i, i, m) } + mVal.SetMapIndex(keyVal, reflect.ValueOf(val)) } + return m, nil } +// ToStringMapIntE casts an interface to a map[string]int{} type. +func ToStringMapIntE(i any) (map[string]int, error) { + return toStringMapIntE(i, ToInt, ToIntE) +} + +// ToStringMapInt64E casts an interface to a map[string]int64{} type. +func ToStringMapInt64E(i interface{}) (map[string]int64, error) { + return toStringMapIntE(i, ToInt64, ToInt64E) +} + // ToSliceE casts an interface to a []interface{} type. func ToSliceE(i interface{}) ([]interface{}, error) { var s []interface{} @@ -1237,14 +1208,13 @@ func ToSliceE(i interface{}) ([]interface{}, error) { } } -// ToBoolSliceE casts an interface to a []bool type. -func ToBoolSliceE(i interface{}) ([]bool, error) { +func toSliceE[T any](i any, fn func(any) (T, error)) ([]T, error) { if i == nil { - return []bool{}, fmt.Errorf("unable to cast %#v of type %T to []bool", i, i) + return []T{}, fmt.Errorf("unable to cast %#v of type %T to %T", i, i, []T{}) } switch v := i.(type) { - case []bool: + case []T: return v, nil } @@ -1252,20 +1222,25 @@ func ToBoolSliceE(i interface{}) ([]bool, error) { switch kind { case reflect.Slice, reflect.Array: s := reflect.ValueOf(i) - a := make([]bool, s.Len()) + a := make([]T, s.Len()) for j := 0; j < s.Len(); j++ { - val, err := ToBoolE(s.Index(j).Interface()) + val, err := fn(s.Index(j).Interface()) if err != nil { - return []bool{}, fmt.Errorf("unable to cast %#v of type %T to []bool", i, i) + return []T{}, fmt.Errorf("unable to cast %#v of type %T to %T", i, i, []T{}) } a[j] = val } return a, nil default: - return []bool{}, fmt.Errorf("unable to cast %#v of type %T to []bool", i, i) + return []T{}, fmt.Errorf("unable to cast %#v of type %T to %T", i, i, []T{}) } } +// ToBoolSliceE casts an interface to a []bool type. +func ToBoolSliceE(i interface{}) ([]bool, error) { + return toSliceE(i, ToBoolE) +} + // ToStringSliceE casts an interface to a []string type. func ToStringSliceE(i interface{}) ([]string, error) { var a []string @@ -1298,6 +1273,26 @@ func ToStringSliceE(i interface{}) ([]string, error) { a = append(a, ToString(u)) } return a, nil + case []uint8: + for _, u := range v { + a = append(a, ToString(u)) + } + return a, nil + case []uint: + for _, u := range v { + a = append(a, ToString(u)) + } + return a, nil + case []uint32: + for _, u := range v { + a = append(a, ToString(u)) + } + return a, nil + case []uint64: + for _, u := range v { + a = append(a, ToString(u)) + } + return a, nil case []float32: for _, u := range v { a = append(a, ToString(u)) @@ -1328,60 +1323,27 @@ func ToStringSliceE(i interface{}) ([]string, error) { // ToIntSliceE casts an interface to a []int type. func ToIntSliceE(i interface{}) ([]int, error) { - if i == nil { - return []int{}, fmt.Errorf("unable to cast %#v of type %T to []int", i, i) - } + return toSliceE(i, ToIntE) +} - switch v := i.(type) { - case []int: - return v, nil - } +// ToUintSliceE casts an interface to a []uint type. +func ToUintSliceE(i interface{}) ([]uint, error) { + return toSliceE(i, ToUintE) +} - kind := reflect.TypeOf(i).Kind() - switch kind { - case reflect.Slice, reflect.Array: - s := reflect.ValueOf(i) - a := make([]int, s.Len()) - for j := 0; j < s.Len(); j++ { - val, err := ToIntE(s.Index(j).Interface()) - if err != nil { - return []int{}, fmt.Errorf("unable to cast %#v of type %T to []int", i, i) - } - a[j] = val - } - return a, nil - default: - return []int{}, fmt.Errorf("unable to cast %#v of type %T to []int", i, i) - } +// ToFloat64SliceE casts an interface to a []float64 type. +func ToFloat64SliceE(i interface{}) ([]float64, error) { + return toSliceE(i, ToFloat64E) +} + +// ToInt64SliceE casts an interface to a []int64 type. +func ToInt64SliceE(i interface{}) ([]int64, error) { + return toSliceE(i, ToInt64E) } // ToDurationSliceE casts an interface to a []time.Duration type. func ToDurationSliceE(i interface{}) ([]time.Duration, error) { - if i == nil { - return []time.Duration{}, fmt.Errorf("unable to cast %#v of type %T to []time.Duration", i, i) - } - - switch v := i.(type) { - case []time.Duration: - return v, nil - } - - kind := reflect.TypeOf(i).Kind() - switch kind { - case reflect.Slice, reflect.Array: - s := reflect.ValueOf(i) - a := make([]time.Duration, s.Len()) - for j := 0; j < s.Len(); j++ { - val, err := ToDurationE(s.Index(j).Interface()) - if err != nil { - return []time.Duration{}, fmt.Errorf("unable to cast %#v of type %T to []time.Duration", i, i) - } - a[j] = val - } - return a, nil - default: - return []time.Duration{}, fmt.Errorf("unable to cast %#v of type %T to []time.Duration", i, i) - } + return toSliceE(i, ToDurationE) } // StringToDate attempts to parse a string into a time.Time type using a diff --git a/vendor/github.com/tdewolff/parse/v2/binary.go b/vendor/github.com/tdewolff/parse/v2/binary.go index c412bd997..7247e6e10 100644 --- a/vendor/github.com/tdewolff/parse/v2/binary.go +++ b/vendor/github.com/tdewolff/parse/v2/binary.go @@ -574,6 +574,16 @@ func (r *BinaryReader2) Read(b []byte) (int, error) { return n, err } +// ReadAt complies with io.ReaderAt. +func (r *BinaryReader2) ReadAt(b []byte, off int64) (int, error) { + data, err := r.f.Bytes(len(b), off) + if err != nil && err != io.EOF { + return 0, err + } + n := copy(b, data) + return n, err +} + // ReadBytes reads n bytes. func (r *BinaryReader2) ReadBytes(n int) []byte { data, err := r.f.Bytes(n, r.pos) diff --git a/vendor/github.com/tdewolff/parse/v2/binary_unix.go b/vendor/github.com/tdewolff/parse/v2/binary_unix.go index 4a7218690..70bb8767f 100644 --- a/vendor/github.com/tdewolff/parse/v2/binary_unix.go +++ b/vendor/github.com/tdewolff/parse/v2/binary_unix.go @@ -22,12 +22,12 @@ func newBinaryReaderMmap(filename string) (*binaryReaderMmap, error) { } defer f.Close() - fi, err := f.Stat() + info, err := f.Stat() if err != nil { return nil, err } - size := fi.Size() + size := info.Size() if size == 0 { // Treat (size == 0) as a special case, avoiding the syscall, since // "man 2 mmap" says "the length... must be greater than 0". @@ -38,9 +38,9 @@ func newBinaryReaderMmap(filename string) (*binaryReaderMmap, error) { data: make([]byte, 0), }, nil } else if size < 0 { - return nil, fmt.Errorf("mmap: file %q has negative size", filename) + return nil, fmt.Errorf("mmap: file %s has negative size", filename) } else if size != int64(int(size)) { - return nil, fmt.Errorf("mmap: file %q is too large", filename) + return nil, fmt.Errorf("mmap: file %s is too large", filename) } data, err := syscall.Mmap(int(f.Fd()), 0, int(size), syscall.PROT_READ, syscall.MAP_SHARED) diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/number.go b/vendor/github.com/tdewolff/parse/v2/strconv/number.go index 9f768dbdb..eb2a909b2 100644 --- a/vendor/github.com/tdewolff/parse/v2/strconv/number.go +++ b/vendor/github.com/tdewolff/parse/v2/strconv/number.go @@ -10,7 +10,7 @@ import ( func ParseNumber(b []byte, groupSym rune, decSym rune) (int64, int, int) { n, dec := 0, 0 sign := int64(1) - price := int64(0) + num := int64(0) hasDecimals := false if 0 < len(b) && b[0] == '-' { sign = -1 @@ -19,13 +19,13 @@ func ParseNumber(b []byte, groupSym rune, decSym rune) (int64, int, int) { for n < len(b) { if '0' <= b[n] && b[n] <= '9' { digit := sign * int64(b[n]-'0') - if sign == 1 && (math.MaxInt64/10 < price || math.MaxInt64-digit < price*10) { + if sign == 1 && (math.MaxInt64/10 < num || math.MaxInt64-digit < num*10) { break - } else if sign == -1 && (price < math.MinInt64/10 || price*10 < math.MinInt64-digit) { + } else if sign == -1 && (num < math.MinInt64/10 || num*10 < math.MinInt64-digit) { break } - price *= 10 - price += digit + num *= 10 + num += digit if hasDecimals { dec++ } @@ -39,11 +39,11 @@ func ParseNumber(b []byte, groupSym rune, decSym rune) (int64, int, int) { break } } - return price, dec, n + return num, dec, n } // AppendNumber will append an int64 formatted as a number with the given number of decimal digits. -func AppendNumber(b []byte, price int64, dec int, groupSize int, groupSym rune, decSym rune) []byte { +func AppendNumber(b []byte, num int64, dec int, groupSize int, groupSym rune, decSym rune) []byte { if dec < 0 { dec = 0 } @@ -55,12 +55,12 @@ func AppendNumber(b []byte, price int64, dec int, groupSize int, groupSym rune, } sign := int64(1) - if price < 0 { + if num < 0 { sign = -1 } // calculate size - n := LenInt(price) + n := LenInt(num) if dec < n && 0 < groupSize && groupSym != 0 { n += utf8.RuneLen(groupSym) * (n - dec - 1) / groupSize } @@ -86,8 +86,8 @@ func AppendNumber(b []byte, price int64, dec int, groupSize int, groupSym rune, i += n - 1 if 0 < dec { for 0 < dec { - c := byte(sign*(price%10)) + '0' - price /= 10 + c := byte(sign*(num%10)) + '0' + num /= 10 b[i] = c dec-- i-- @@ -97,7 +97,7 @@ func AppendNumber(b []byte, price int64, dec int, groupSize int, groupSym rune, } // print integer-part - if price == 0 { + if num == 0 { b[i] = '0' if sign == -1 { b[i-1] = '-' @@ -105,14 +105,14 @@ func AppendNumber(b []byte, price int64, dec int, groupSize int, groupSym rune, return b } j := 0 - for price != 0 { + for num != 0 { if 0 < groupSize && groupSym != 0 && 0 < j && j%groupSize == 0 { i -= utf8.RuneLen(groupSym) utf8.EncodeRune(b[i+1:], groupSym) } - c := byte(sign*(price%10)) + '0' - price /= 10 + c := byte(sign*(num%10)) + '0' + num /= 10 b[i] = c i-- j++ |
