mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-07 05:52:26 +00:00
Project structure refactor:
- Change package name general_server to gateway - Changing the structure of directories and packages - Adding vendor to the project
This commit is contained in:
21
vendor/github.com/go-viper/mapstructure/v2/.editorconfig
generated
vendored
Normal file
21
vendor/github.com/go-viper/mapstructure/v2/.editorconfig
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
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
|
||||
|
||||
[{Makefile,*.mk}]
|
||||
indent_style = tab
|
||||
|
||||
[*.nix]
|
||||
indent_size = 2
|
||||
|
||||
[.golangci.yaml]
|
||||
indent_size = 2
|
||||
4
vendor/github.com/go-viper/mapstructure/v2/.envrc
generated
vendored
Normal file
4
vendor/github.com/go-viper/mapstructure/v2/.envrc
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
|
||||
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
|
||||
fi
|
||||
use flake . --impure
|
||||
6
vendor/github.com/go-viper/mapstructure/v2/.gitignore
generated
vendored
Normal file
6
vendor/github.com/go-viper/mapstructure/v2/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/.devenv/
|
||||
/.direnv/
|
||||
/.pre-commit-config.yaml
|
||||
/bin/
|
||||
/build/
|
||||
/var/
|
||||
48
vendor/github.com/go-viper/mapstructure/v2/.golangci.yaml
generated
vendored
Normal file
48
vendor/github.com/go-viper/mapstructure/v2/.golangci.yaml
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
version: "2"
|
||||
|
||||
run:
|
||||
timeout: 10m
|
||||
|
||||
linters:
|
||||
enable:
|
||||
- govet
|
||||
- ineffassign
|
||||
# - misspell
|
||||
- nolintlint
|
||||
# - revive
|
||||
|
||||
disable:
|
||||
- errcheck
|
||||
- staticcheck
|
||||
- unused
|
||||
|
||||
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
|
||||
gofmt:
|
||||
simplify: true
|
||||
rewrite-rules:
|
||||
- pattern: interface{}
|
||||
replacement: any
|
||||
|
||||
exclusions:
|
||||
paths:
|
||||
- internal/
|
||||
104
vendor/github.com/go-viper/mapstructure/v2/CHANGELOG.md
generated
vendored
Normal file
104
vendor/github.com/go-viper/mapstructure/v2/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
> [!WARNING]
|
||||
> As of v2 of this library, change log can be found in GitHub releases.
|
||||
|
||||
## 1.5.1
|
||||
|
||||
* Wrap errors so they're compatible with `errors.Is` and `errors.As` [GH-282]
|
||||
* Fix map of slices not decoding properly in certain cases. [GH-266]
|
||||
|
||||
## 1.5.0
|
||||
|
||||
* New option `IgnoreUntaggedFields` to ignore decoding to any fields
|
||||
without `mapstructure` (or the configured tag name) set [GH-277]
|
||||
* New option `ErrorUnset` which makes it an error if any fields
|
||||
in a target struct are not set by the decoding process. [GH-225]
|
||||
* New function `OrComposeDecodeHookFunc` to help compose decode hooks. [GH-240]
|
||||
* Decoding to slice from array no longer crashes [GH-265]
|
||||
* Decode nested struct pointers to map [GH-271]
|
||||
* Fix issue where `,squash` was ignored if `Squash` option was set. [GH-280]
|
||||
* Fix issue where fields with `,omitempty` would sometimes decode
|
||||
into a map with an empty string key [GH-281]
|
||||
|
||||
## 1.4.3
|
||||
|
||||
* Fix cases where `json.Number` didn't decode properly [GH-261]
|
||||
|
||||
## 1.4.2
|
||||
|
||||
* Custom name matchers to support any sort of casing, formatting, etc. for
|
||||
field names. [GH-250]
|
||||
* Fix possible panic in ComposeDecodeHookFunc [GH-251]
|
||||
|
||||
## 1.4.1
|
||||
|
||||
* Fix regression where `*time.Time` value would be set to empty and not be sent
|
||||
to decode hooks properly [GH-232]
|
||||
|
||||
## 1.4.0
|
||||
|
||||
* A new decode hook type `DecodeHookFuncValue` has been added that has
|
||||
access to the full values. [GH-183]
|
||||
* Squash is now supported with embedded fields that are struct pointers [GH-205]
|
||||
* Empty strings will convert to 0 for all numeric types when weakly decoding [GH-206]
|
||||
|
||||
## 1.3.3
|
||||
|
||||
* Decoding maps from maps creates a settable value for decode hooks [GH-203]
|
||||
|
||||
## 1.3.2
|
||||
|
||||
* Decode into interface type with a struct value is supported [GH-187]
|
||||
|
||||
## 1.3.1
|
||||
|
||||
* Squash should only squash embedded structs. [GH-194]
|
||||
|
||||
## 1.3.0
|
||||
|
||||
* Added `",omitempty"` support. This will ignore zero values in the source
|
||||
structure when encoding. [GH-145]
|
||||
|
||||
## 1.2.3
|
||||
|
||||
* Fix duplicate entries in Keys list with pointer values. [GH-185]
|
||||
|
||||
## 1.2.2
|
||||
|
||||
* Do not add unsettable (unexported) values to the unused metadata key
|
||||
or "remain" value. [GH-150]
|
||||
|
||||
## 1.2.1
|
||||
|
||||
* Go modules checksum mismatch fix
|
||||
|
||||
## 1.2.0
|
||||
|
||||
* Added support to capture unused values in a field using the `",remain"` value
|
||||
in the mapstructure tag. There is an example to showcase usage.
|
||||
* Added `DecoderConfig` option to always squash embedded structs
|
||||
* `json.Number` can decode into `uint` types
|
||||
* Empty slices are preserved and not replaced with nil slices
|
||||
* Fix panic that can occur in when decoding a map into a nil slice of structs
|
||||
* Improved package documentation for godoc
|
||||
|
||||
## 1.1.2
|
||||
|
||||
* Fix error when decode hook decodes interface implementation into interface
|
||||
type. [GH-140]
|
||||
|
||||
## 1.1.1
|
||||
|
||||
* Fix panic that can happen in `decodePtr`
|
||||
|
||||
## 1.1.0
|
||||
|
||||
* Added `StringToIPHookFunc` to convert `string` to `net.IP` and `net.IPNet` [GH-133]
|
||||
* Support struct to struct decoding [GH-137]
|
||||
* If source map value is nil, then destination map value is nil (instead of empty)
|
||||
* If source slice value is nil, then destination slice value is nil (instead of empty)
|
||||
* If source pointer is nil, then destination pointer is set to nil (instead of
|
||||
allocated zero value of type)
|
||||
|
||||
## 1.0.0
|
||||
|
||||
* Initial tagged stable release.
|
||||
21
vendor/github.com/go-viper/mapstructure/v2/LICENSE
generated
vendored
Normal file
21
vendor/github.com/go-viper/mapstructure/v2/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Mitchell Hashimoto
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
81
vendor/github.com/go-viper/mapstructure/v2/README.md
generated
vendored
Normal file
81
vendor/github.com/go-viper/mapstructure/v2/README.md
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
# mapstructure
|
||||
|
||||
[](https://github.com/go-viper/mapstructure/actions/workflows/ci.yaml)
|
||||
[](https://pkg.go.dev/mod/github.com/go-viper/mapstructure/v2)
|
||||

|
||||
[](https://deps.dev/go/github.com%252Fgo-viper%252Fmapstructure%252Fv2)
|
||||
|
||||
mapstructure is a Go library for decoding generic map values to structures
|
||||
and vice versa, while providing helpful error handling.
|
||||
|
||||
This library is most useful when decoding values from some data stream (JSON,
|
||||
Gob, etc.) where you don't _quite_ know the structure of the underlying data
|
||||
until you read a part of it. You can therefore read a `map[string]interface{}`
|
||||
and use this library to decode it into the proper underlying native Go
|
||||
structure.
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
go get github.com/go-viper/mapstructure/v2
|
||||
```
|
||||
|
||||
## Migrating from `github.com/mitchellh/mapstructure`
|
||||
|
||||
[@mitchehllh](https://github.com/mitchellh) announced his intent to archive some of his unmaintained projects (see [here](https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc) and [here](https://github.com/mitchellh/mapstructure/issues/349)). This is a repository achieved the "blessed fork" status.
|
||||
|
||||
You can migrate to this package by changing your import paths in your Go files to `github.com/go-viper/mapstructure/v2`.
|
||||
The API is the same, so you don't need to change anything else.
|
||||
|
||||
Here is a script that can help you with the migration:
|
||||
|
||||
```shell
|
||||
sed -i 's|github.com/mitchellh/mapstructure|github.com/go-viper/mapstructure/v2|g' $(find . -type f -name '*.go')
|
||||
```
|
||||
|
||||
If you need more time to migrate your code, that is absolutely fine.
|
||||
|
||||
Some of the latest fixes are backported to the v1 release branch of this package, so you can use the Go modules `replace` feature until you are ready to migrate:
|
||||
|
||||
```shell
|
||||
replace github.com/mitchellh/mapstructure => github.com/go-viper/mapstructure v1.6.0
|
||||
```
|
||||
|
||||
## Usage & Example
|
||||
|
||||
For usage and examples see the [documentation](https://pkg.go.dev/mod/github.com/go-viper/mapstructure/v2).
|
||||
|
||||
The `Decode` function has examples associated with it there.
|
||||
|
||||
## But Why?!
|
||||
|
||||
Go offers fantastic standard libraries for decoding formats such as JSON.
|
||||
The standard method is to have a struct pre-created, and populate that struct
|
||||
from the bytes of the encoded format. This is great, but the problem is if
|
||||
you have configuration or an encoding that changes slightly depending on
|
||||
specific fields. For example, consider this JSON:
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "person",
|
||||
"name": "Mitchell"
|
||||
}
|
||||
```
|
||||
|
||||
Perhaps we can't populate a specific structure without first reading
|
||||
the "type" field from the JSON. We could always do two passes over the
|
||||
decoding of the JSON (reading the "type" first, and the rest later).
|
||||
However, it is much simpler to just decode this into a `map[string]interface{}`
|
||||
structure, read the "type" key, then use something like this library
|
||||
to decode it into the proper structure.
|
||||
|
||||
## Credits
|
||||
|
||||
Mapstructure was originally created by [@mitchellh](https://github.com/mitchellh).
|
||||
This is a maintained fork of the original library.
|
||||
|
||||
Read more about the reasons for the fork [here](https://github.com/mitchellh/mapstructure/issues/349).
|
||||
|
||||
## License
|
||||
|
||||
The project is licensed under the [MIT License](LICENSE).
|
||||
714
vendor/github.com/go-viper/mapstructure/v2/decode_hooks.go
generated
vendored
Normal file
714
vendor/github.com/go-viper/mapstructure/v2/decode_hooks.go
generated
vendored
Normal file
@@ -0,0 +1,714 @@
|
||||
package mapstructure
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// typedDecodeHook takes a raw DecodeHookFunc (an any) and turns
|
||||
// it into the proper DecodeHookFunc type, such as DecodeHookFuncType.
|
||||
func typedDecodeHook(h DecodeHookFunc) DecodeHookFunc {
|
||||
// Create variables here so we can reference them with the reflect pkg
|
||||
var f1 DecodeHookFuncType
|
||||
var f2 DecodeHookFuncKind
|
||||
var f3 DecodeHookFuncValue
|
||||
|
||||
// Fill in the variables into this interface and the rest is done
|
||||
// automatically using the reflect package.
|
||||
potential := []any{f1, f2, f3}
|
||||
|
||||
v := reflect.ValueOf(h)
|
||||
vt := v.Type()
|
||||
for _, raw := range potential {
|
||||
pt := reflect.ValueOf(raw).Type()
|
||||
if vt.ConvertibleTo(pt) {
|
||||
return v.Convert(pt).Interface()
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// cachedDecodeHook takes a raw DecodeHookFunc (an any) and turns
|
||||
// it into a closure to be used directly
|
||||
// if the type fails to convert we return a closure always erroring to keep the previous behaviour
|
||||
func cachedDecodeHook(raw DecodeHookFunc) func(from reflect.Value, to reflect.Value) (any, error) {
|
||||
switch f := typedDecodeHook(raw).(type) {
|
||||
case DecodeHookFuncType:
|
||||
return func(from reflect.Value, to reflect.Value) (any, error) {
|
||||
return f(from.Type(), to.Type(), from.Interface())
|
||||
}
|
||||
case DecodeHookFuncKind:
|
||||
return func(from reflect.Value, to reflect.Value) (any, error) {
|
||||
return f(from.Kind(), to.Kind(), from.Interface())
|
||||
}
|
||||
case DecodeHookFuncValue:
|
||||
return func(from reflect.Value, to reflect.Value) (any, error) {
|
||||
return f(from, to)
|
||||
}
|
||||
default:
|
||||
return func(from reflect.Value, to reflect.Value) (any, error) {
|
||||
return nil, errors.New("invalid decode hook signature")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DecodeHookExec executes the given decode hook. This should be used
|
||||
// since it'll naturally degrade to the older backwards compatible DecodeHookFunc
|
||||
// that took reflect.Kind instead of reflect.Type.
|
||||
func DecodeHookExec(
|
||||
raw DecodeHookFunc,
|
||||
from reflect.Value, to reflect.Value,
|
||||
) (any, error) {
|
||||
switch f := typedDecodeHook(raw).(type) {
|
||||
case DecodeHookFuncType:
|
||||
return f(from.Type(), to.Type(), from.Interface())
|
||||
case DecodeHookFuncKind:
|
||||
return f(from.Kind(), to.Kind(), from.Interface())
|
||||
case DecodeHookFuncValue:
|
||||
return f(from, to)
|
||||
default:
|
||||
return nil, errors.New("invalid decode hook signature")
|
||||
}
|
||||
}
|
||||
|
||||
// ComposeDecodeHookFunc creates a single DecodeHookFunc that
|
||||
// automatically composes multiple DecodeHookFuncs.
|
||||
//
|
||||
// The composed funcs are called in order, with the result of the
|
||||
// previous transformation.
|
||||
func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc {
|
||||
cached := make([]func(from reflect.Value, to reflect.Value) (any, error), 0, len(fs))
|
||||
for _, f := range fs {
|
||||
cached = append(cached, cachedDecodeHook(f))
|
||||
}
|
||||
return func(f reflect.Value, t reflect.Value) (any, error) {
|
||||
var err error
|
||||
data := f.Interface()
|
||||
|
||||
newFrom := f
|
||||
for _, c := range cached {
|
||||
data, err = c(newFrom, t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v, ok := data.(reflect.Value); ok {
|
||||
newFrom = v
|
||||
} else {
|
||||
newFrom = reflect.ValueOf(data)
|
||||
}
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
|
||||
// OrComposeDecodeHookFunc executes all input hook functions until one of them returns no error. In that case its value is returned.
|
||||
// If all hooks return an error, OrComposeDecodeHookFunc returns an error concatenating all error messages.
|
||||
func OrComposeDecodeHookFunc(ff ...DecodeHookFunc) DecodeHookFunc {
|
||||
cached := make([]func(from reflect.Value, to reflect.Value) (any, error), 0, len(ff))
|
||||
for _, f := range ff {
|
||||
cached = append(cached, cachedDecodeHook(f))
|
||||
}
|
||||
return func(a, b reflect.Value) (any, error) {
|
||||
var allErrs string
|
||||
var out any
|
||||
var err error
|
||||
|
||||
for _, c := range cached {
|
||||
out, err = c(a, b)
|
||||
if err != nil {
|
||||
allErrs += err.Error() + "\n"
|
||||
continue
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
return nil, errors.New(allErrs)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToSliceHookFunc returns a DecodeHookFunc that converts
|
||||
// string to []string by splitting on the given sep.
|
||||
func StringToSliceHookFunc(sep string) DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
if t != reflect.SliceOf(f) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
raw := data.(string)
|
||||
if raw == "" {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
return strings.Split(raw, sep), nil
|
||||
}
|
||||
}
|
||||
|
||||
// StringToWeakSliceHookFunc brings back the old (pre-v2) behavior of [StringToSliceHookFunc].
|
||||
//
|
||||
// As of mapstructure v2.0.0 [StringToSliceHookFunc] checks if the return type is a string slice.
|
||||
// This function removes that check.
|
||||
func StringToWeakSliceHookFunc(sep string) DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Slice {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
raw := data.(string)
|
||||
if raw == "" {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
return strings.Split(raw, sep), nil
|
||||
}
|
||||
}
|
||||
|
||||
// StringToTimeDurationHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to time.Duration.
|
||||
func StringToTimeDurationHookFunc() DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
if t != reflect.TypeOf(time.Duration(5)) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
d, err := time.ParseDuration(data.(string))
|
||||
|
||||
return d, wrapTimeParseDurationError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToTimeLocationHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to *time.Location.
|
||||
func StringToTimeLocationHookFunc() DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
if t != reflect.TypeOf(time.Local) {
|
||||
return data, nil
|
||||
}
|
||||
d, err := time.LoadLocation(data.(string))
|
||||
|
||||
return d, wrapTimeParseLocationError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToURLHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to *url.URL.
|
||||
func StringToURLHookFunc() DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
if t != reflect.TypeOf(&url.URL{}) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
u, err := url.Parse(data.(string))
|
||||
|
||||
return u, wrapUrlError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToIPHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to net.IP
|
||||
func StringToIPHookFunc() DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
if t != reflect.TypeOf(net.IP{}) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
ip := net.ParseIP(data.(string))
|
||||
if ip == nil {
|
||||
return net.IP{}, fmt.Errorf("failed parsing ip")
|
||||
}
|
||||
|
||||
return ip, nil
|
||||
}
|
||||
}
|
||||
|
||||
// StringToIPNetHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to net.IPNet
|
||||
func StringToIPNetHookFunc() DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
if t != reflect.TypeOf(net.IPNet{}) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
_, net, err := net.ParseCIDR(data.(string))
|
||||
return net, wrapNetParseError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToTimeHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to time.Time.
|
||||
func StringToTimeHookFunc(layout string) DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
if t != reflect.TypeOf(time.Time{}) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
ti, err := time.Parse(layout, data.(string))
|
||||
|
||||
return ti, wrapTimeParseError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// WeaklyTypedHook is a DecodeHookFunc which adds support for weak typing to
|
||||
// the decoder.
|
||||
//
|
||||
// Note that this is significantly different from the WeaklyTypedInput option
|
||||
// of the DecoderConfig.
|
||||
func WeaklyTypedHook(
|
||||
f reflect.Kind,
|
||||
t reflect.Kind,
|
||||
data any,
|
||||
) (any, error) {
|
||||
dataVal := reflect.ValueOf(data)
|
||||
switch t {
|
||||
case reflect.String:
|
||||
switch f {
|
||||
case reflect.Bool:
|
||||
if dataVal.Bool() {
|
||||
return "1", nil
|
||||
}
|
||||
return "0", nil
|
||||
case reflect.Float32:
|
||||
return strconv.FormatFloat(dataVal.Float(), 'f', -1, 64), nil
|
||||
case reflect.Int:
|
||||
return strconv.FormatInt(dataVal.Int(), 10), nil
|
||||
case reflect.Slice:
|
||||
dataType := dataVal.Type()
|
||||
elemKind := dataType.Elem().Kind()
|
||||
if elemKind == reflect.Uint8 {
|
||||
return string(dataVal.Interface().([]uint8)), nil
|
||||
}
|
||||
case reflect.Uint:
|
||||
return strconv.FormatUint(dataVal.Uint(), 10), nil
|
||||
}
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func RecursiveStructToMapHookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Value, t reflect.Value) (any, error) {
|
||||
if f.Kind() != reflect.Struct {
|
||||
return f.Interface(), nil
|
||||
}
|
||||
|
||||
var i any = struct{}{}
|
||||
if t.Type() != reflect.TypeOf(&i).Elem() {
|
||||
return f.Interface(), nil
|
||||
}
|
||||
|
||||
m := make(map[string]any)
|
||||
t.Set(reflect.ValueOf(m))
|
||||
|
||||
return f.Interface(), nil
|
||||
}
|
||||
}
|
||||
|
||||
// TextUnmarshallerHookFunc returns a DecodeHookFunc that applies
|
||||
// strings to the UnmarshalText function, when the target type
|
||||
// implements the encoding.TextUnmarshaler interface
|
||||
func TextUnmarshallerHookFunc() DecodeHookFuncType {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
result := reflect.New(t).Interface()
|
||||
unmarshaller, ok := result.(encoding.TextUnmarshaler)
|
||||
if !ok {
|
||||
return data, nil
|
||||
}
|
||||
str, ok := data.(string)
|
||||
if !ok {
|
||||
str = reflect.Indirect(reflect.ValueOf(&data)).Elem().String()
|
||||
}
|
||||
if err := unmarshaller.UnmarshalText([]byte(str)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
// StringToNetIPAddrHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to netip.Addr.
|
||||
func StringToNetIPAddrHookFunc() DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
if t != reflect.TypeOf(netip.Addr{}) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
addr, err := netip.ParseAddr(data.(string))
|
||||
|
||||
return addr, wrapNetIPParseAddrError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToNetIPAddrPortHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to netip.AddrPort.
|
||||
func StringToNetIPAddrPortHookFunc() DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
if t != reflect.TypeOf(netip.AddrPort{}) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
addrPort, err := netip.ParseAddrPort(data.(string))
|
||||
|
||||
return addrPort, wrapNetIPParseAddrPortError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToNetIPPrefixHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to netip.Prefix.
|
||||
func StringToNetIPPrefixHookFunc() DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
if t != reflect.TypeOf(netip.Prefix{}) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
prefix, err := netip.ParsePrefix(data.(string))
|
||||
|
||||
return prefix, wrapNetIPParsePrefixError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToBasicTypeHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to basic types.
|
||||
// int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint, float32, float64, bool, byte, rune, complex64, complex128
|
||||
func StringToBasicTypeHookFunc() DecodeHookFunc {
|
||||
return ComposeDecodeHookFunc(
|
||||
StringToInt8HookFunc(),
|
||||
StringToUint8HookFunc(),
|
||||
StringToInt16HookFunc(),
|
||||
StringToUint16HookFunc(),
|
||||
StringToInt32HookFunc(),
|
||||
StringToUint32HookFunc(),
|
||||
StringToInt64HookFunc(),
|
||||
StringToUint64HookFunc(),
|
||||
StringToIntHookFunc(),
|
||||
StringToUintHookFunc(),
|
||||
StringToFloat32HookFunc(),
|
||||
StringToFloat64HookFunc(),
|
||||
StringToBoolHookFunc(),
|
||||
// byte and rune are aliases for uint8 and int32 respectively
|
||||
// StringToByteHookFunc(),
|
||||
// StringToRuneHookFunc(),
|
||||
StringToComplex64HookFunc(),
|
||||
StringToComplex128HookFunc(),
|
||||
)
|
||||
}
|
||||
|
||||
// StringToInt8HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to int8.
|
||||
func StringToInt8HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Int8 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
i64, err := strconv.ParseInt(data.(string), 0, 8)
|
||||
return int8(i64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToUint8HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to uint8.
|
||||
func StringToUint8HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Uint8 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
u64, err := strconv.ParseUint(data.(string), 0, 8)
|
||||
return uint8(u64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToInt16HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to int16.
|
||||
func StringToInt16HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Int16 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
i64, err := strconv.ParseInt(data.(string), 0, 16)
|
||||
return int16(i64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToUint16HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to uint16.
|
||||
func StringToUint16HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Uint16 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
u64, err := strconv.ParseUint(data.(string), 0, 16)
|
||||
return uint16(u64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToInt32HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to int32.
|
||||
func StringToInt32HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Int32 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
i64, err := strconv.ParseInt(data.(string), 0, 32)
|
||||
return int32(i64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToUint32HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to uint32.
|
||||
func StringToUint32HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Uint32 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
u64, err := strconv.ParseUint(data.(string), 0, 32)
|
||||
return uint32(u64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToInt64HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to int64.
|
||||
func StringToInt64HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Int64 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
i64, err := strconv.ParseInt(data.(string), 0, 64)
|
||||
return int64(i64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToUint64HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to uint64.
|
||||
func StringToUint64HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Uint64 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
u64, err := strconv.ParseUint(data.(string), 0, 64)
|
||||
return uint64(u64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToIntHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to int.
|
||||
func StringToIntHookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Int {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
i64, err := strconv.ParseInt(data.(string), 0, 0)
|
||||
return int(i64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToUintHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to uint.
|
||||
func StringToUintHookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Uint {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
u64, err := strconv.ParseUint(data.(string), 0, 0)
|
||||
return uint(u64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToFloat32HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to float32.
|
||||
func StringToFloat32HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Float32 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
f64, err := strconv.ParseFloat(data.(string), 32)
|
||||
return float32(f64), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToFloat64HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to float64.
|
||||
func StringToFloat64HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Float64 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
f64, err := strconv.ParseFloat(data.(string), 64)
|
||||
return f64, wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToBoolHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to bool.
|
||||
func StringToBoolHookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Bool {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
b, err := strconv.ParseBool(data.(string))
|
||||
return b, wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToByteHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to byte.
|
||||
func StringToByteHookFunc() DecodeHookFunc {
|
||||
return StringToUint8HookFunc()
|
||||
}
|
||||
|
||||
// StringToRuneHookFunc returns a DecodeHookFunc that converts
|
||||
// strings to rune.
|
||||
func StringToRuneHookFunc() DecodeHookFunc {
|
||||
return StringToInt32HookFunc()
|
||||
}
|
||||
|
||||
// StringToComplex64HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to complex64.
|
||||
func StringToComplex64HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Complex64 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
c128, err := strconv.ParseComplex(data.(string), 64)
|
||||
return complex64(c128), wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// StringToComplex128HookFunc returns a DecodeHookFunc that converts
|
||||
// strings to complex128.
|
||||
func StringToComplex128HookFunc() DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
|
||||
if f.Kind() != reflect.String || t.Kind() != reflect.Complex128 {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Convert it by parsing
|
||||
c128, err := strconv.ParseComplex(data.(string), 128)
|
||||
return c128, wrapStrconvNumError(err)
|
||||
}
|
||||
}
|
||||
244
vendor/github.com/go-viper/mapstructure/v2/errors.go
generated
vendored
Normal file
244
vendor/github.com/go-viper/mapstructure/v2/errors.go
generated
vendored
Normal file
@@ -0,0 +1,244 @@
|
||||
package mapstructure
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Error interface is implemented by all errors emitted by mapstructure.
|
||||
//
|
||||
// Use [errors.As] to check if an error implements this interface.
|
||||
type Error interface {
|
||||
error
|
||||
|
||||
mapstructure()
|
||||
}
|
||||
|
||||
// DecodeError is a generic error type that holds information about
|
||||
// a decoding error together with the name of the field that caused the error.
|
||||
type DecodeError struct {
|
||||
name string
|
||||
err error
|
||||
}
|
||||
|
||||
func newDecodeError(name string, err error) *DecodeError {
|
||||
return &DecodeError{
|
||||
name: name,
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *DecodeError) Name() string {
|
||||
return e.name
|
||||
}
|
||||
|
||||
func (e *DecodeError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
func (e *DecodeError) Error() string {
|
||||
return fmt.Sprintf("'%s' %s", e.name, e.err)
|
||||
}
|
||||
|
||||
func (*DecodeError) mapstructure() {}
|
||||
|
||||
// ParseError is an error type that indicates a value could not be parsed
|
||||
// into the expected type.
|
||||
type ParseError struct {
|
||||
Expected reflect.Value
|
||||
Value any
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *ParseError) Error() string {
|
||||
return fmt.Sprintf("cannot parse value as '%s': %s", e.Expected.Type(), e.Err)
|
||||
}
|
||||
|
||||
func (*ParseError) mapstructure() {}
|
||||
|
||||
// UnconvertibleTypeError is an error type that indicates a value could not be
|
||||
// converted to the expected type.
|
||||
type UnconvertibleTypeError struct {
|
||||
Expected reflect.Value
|
||||
Value any
|
||||
}
|
||||
|
||||
func (e *UnconvertibleTypeError) Error() string {
|
||||
return fmt.Sprintf(
|
||||
"expected type '%s', got unconvertible type '%s'",
|
||||
e.Expected.Type(),
|
||||
reflect.TypeOf(e.Value),
|
||||
)
|
||||
}
|
||||
|
||||
func (*UnconvertibleTypeError) mapstructure() {}
|
||||
|
||||
func wrapStrconvNumError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err, ok := err.(*strconv.NumError); ok {
|
||||
return &strconvNumError{Err: err}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
type strconvNumError struct {
|
||||
Err *strconv.NumError
|
||||
}
|
||||
|
||||
func (e *strconvNumError) Error() string {
|
||||
return "strconv." + e.Err.Func + ": " + e.Err.Err.Error()
|
||||
}
|
||||
|
||||
func (e *strconvNumError) Unwrap() error { return e.Err }
|
||||
|
||||
func wrapUrlError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err, ok := err.(*url.Error); ok {
|
||||
return &urlError{Err: err}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
type urlError struct {
|
||||
Err *url.Error
|
||||
}
|
||||
|
||||
func (e *urlError) Error() string {
|
||||
return fmt.Sprintf("%s", e.Err.Err)
|
||||
}
|
||||
|
||||
func (e *urlError) Unwrap() error { return e.Err }
|
||||
|
||||
func wrapNetParseError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err, ok := err.(*net.ParseError); ok {
|
||||
return &netParseError{Err: err}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
type netParseError struct {
|
||||
Err *net.ParseError
|
||||
}
|
||||
|
||||
func (e *netParseError) Error() string {
|
||||
return "invalid " + e.Err.Type
|
||||
}
|
||||
|
||||
func (e *netParseError) Unwrap() error { return e.Err }
|
||||
|
||||
func wrapTimeParseError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err, ok := err.(*time.ParseError); ok {
|
||||
return &timeParseError{Err: err}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
type timeParseError struct {
|
||||
Err *time.ParseError
|
||||
}
|
||||
|
||||
func (e *timeParseError) Error() string {
|
||||
if e.Err.Message == "" {
|
||||
return fmt.Sprintf("parsing time as %q: cannot parse as %q", e.Err.Layout, e.Err.LayoutElem)
|
||||
}
|
||||
|
||||
return "parsing time " + e.Err.Message
|
||||
}
|
||||
|
||||
func (e *timeParseError) Unwrap() error { return e.Err }
|
||||
|
||||
func wrapNetIPParseAddrError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if errMsg := err.Error(); strings.HasPrefix(errMsg, "ParseAddr") {
|
||||
errPieces := strings.Split(errMsg, ": ")
|
||||
|
||||
return fmt.Errorf("ParseAddr: %s", errPieces[len(errPieces)-1])
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func wrapNetIPParseAddrPortError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
errMsg := err.Error()
|
||||
if strings.HasPrefix(errMsg, "invalid port ") {
|
||||
return errors.New("invalid port")
|
||||
} else if strings.HasPrefix(errMsg, "invalid ip:port ") {
|
||||
return errors.New("invalid ip:port")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func wrapNetIPParsePrefixError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if errMsg := err.Error(); strings.HasPrefix(errMsg, "netip.ParsePrefix") {
|
||||
errPieces := strings.Split(errMsg, ": ")
|
||||
|
||||
return fmt.Errorf("netip.ParsePrefix: %s", errPieces[len(errPieces)-1])
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func wrapTimeParseDurationError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
errMsg := err.Error()
|
||||
if strings.HasPrefix(errMsg, "time: unknown unit ") {
|
||||
return errors.New("time: unknown unit")
|
||||
} else if strings.HasPrefix(errMsg, "time: ") {
|
||||
idx := strings.LastIndex(errMsg, " ")
|
||||
|
||||
return errors.New(errMsg[:idx])
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func wrapTimeParseLocationError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
errMsg := err.Error()
|
||||
if strings.Contains(errMsg, "unknown time zone") || strings.HasPrefix(errMsg, "time: unknown format") {
|
||||
return fmt.Errorf("invalid time zone format: %w", err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
294
vendor/github.com/go-viper/mapstructure/v2/flake.lock
generated
vendored
Normal file
294
vendor/github.com/go-viper/mapstructure/v2/flake.lock
generated
vendored
Normal file
@@ -0,0 +1,294 @@
|
||||
{
|
||||
"nodes": {
|
||||
"cachix": {
|
||||
"inputs": {
|
||||
"devenv": [
|
||||
"devenv"
|
||||
],
|
||||
"flake-compat": [
|
||||
"devenv"
|
||||
],
|
||||
"git-hooks": [
|
||||
"devenv"
|
||||
],
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1742042642,
|
||||
"narHash": "sha256-D0gP8srrX0qj+wNYNPdtVJsQuFzIng3q43thnHXQ/es=",
|
||||
"owner": "cachix",
|
||||
"repo": "cachix",
|
||||
"rev": "a624d3eaf4b1d225f918de8543ed739f2f574203",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"ref": "latest",
|
||||
"repo": "cachix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"devenv": {
|
||||
"inputs": {
|
||||
"cachix": "cachix",
|
||||
"flake-compat": "flake-compat",
|
||||
"git-hooks": "git-hooks",
|
||||
"nix": "nix",
|
||||
"nixpkgs": "nixpkgs_3"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1744876578,
|
||||
"narHash": "sha256-8MTBj2REB8t29sIBLpxbR0+AEGJ7f+RkzZPAGsFd40c=",
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"rev": "7ff7c351bba20d0615be25ecdcbcf79b57b85fe1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1733328505,
|
||||
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": [
|
||||
"devenv",
|
||||
"nix",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1712014858,
|
||||
"narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "9126214d0a59633752a136528f5f3b9aa8565b7d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-parts_2": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1743550720,
|
||||
"narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "c621e8422220273271f52058f618c94e405bb0f5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"git-hooks": {
|
||||
"inputs": {
|
||||
"flake-compat": [
|
||||
"devenv"
|
||||
],
|
||||
"gitignore": "gitignore",
|
||||
"nixpkgs": [
|
||||
"devenv",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1742649964,
|
||||
"narHash": "sha256-DwOTp7nvfi8mRfuL1escHDXabVXFGT1VlPD1JHrtrco=",
|
||||
"owner": "cachix",
|
||||
"repo": "git-hooks.nix",
|
||||
"rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "git-hooks.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gitignore": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"devenv",
|
||||
"git-hooks",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1709087332,
|
||||
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"libgit2": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1697646580,
|
||||
"narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=",
|
||||
"owner": "libgit2",
|
||||
"repo": "libgit2",
|
||||
"rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "libgit2",
|
||||
"repo": "libgit2",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix": {
|
||||
"inputs": {
|
||||
"flake-compat": [
|
||||
"devenv"
|
||||
],
|
||||
"flake-parts": "flake-parts",
|
||||
"libgit2": "libgit2",
|
||||
"nixpkgs": "nixpkgs_2",
|
||||
"nixpkgs-23-11": [
|
||||
"devenv"
|
||||
],
|
||||
"nixpkgs-regression": [
|
||||
"devenv"
|
||||
],
|
||||
"pre-commit-hooks": [
|
||||
"devenv"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1741798497,
|
||||
"narHash": "sha256-E3j+3MoY8Y96mG1dUIiLFm2tZmNbRvSiyN7CrSKuAVg=",
|
||||
"owner": "domenkozar",
|
||||
"repo": "nix",
|
||||
"rev": "f3f44b2baaf6c4c6e179de8cbb1cc6db031083cd",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "domenkozar",
|
||||
"ref": "devenv-2.24",
|
||||
"repo": "nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1733212471,
|
||||
"narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "55d15ad12a74eb7d4646254e13638ad0c4128776",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"lastModified": 1743296961,
|
||||
"narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1717432640,
|
||||
"narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "88269ab3044128b7c2f4c7d68448b2fb50456870",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "release-24.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_3": {
|
||||
"locked": {
|
||||
"lastModified": 1733477122,
|
||||
"narHash": "sha256-qamMCz5mNpQmgBwc8SB5tVMlD5sbwVIToVZtSxMph9s=",
|
||||
"owner": "cachix",
|
||||
"repo": "devenv-nixpkgs",
|
||||
"rev": "7bd9e84d0452f6d2e63b6e6da29fe73fac951857",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"ref": "rolling",
|
||||
"repo": "devenv-nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_4": {
|
||||
"locked": {
|
||||
"lastModified": 1744536153,
|
||||
"narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"devenv": "devenv",
|
||||
"flake-parts": "flake-parts_2",
|
||||
"nixpkgs": "nixpkgs_4"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
46
vendor/github.com/go-viper/mapstructure/v2/flake.nix
generated
vendored
Normal file
46
vendor/github.com/go-viper/mapstructure/v2/flake.nix
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
devenv.url = "github:cachix/devenv";
|
||||
};
|
||||
|
||||
outputs =
|
||||
inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [
|
||||
inputs.devenv.flakeModule
|
||||
];
|
||||
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
perSystem =
|
||||
{ pkgs, ... }:
|
||||
rec {
|
||||
devenv.shells = {
|
||||
default = {
|
||||
languages = {
|
||||
go.enable = true;
|
||||
};
|
||||
|
||||
pre-commit.hooks = {
|
||||
nixpkgs-fmt.enable = true;
|
||||
};
|
||||
|
||||
packages = with pkgs; [
|
||||
golangci-lint
|
||||
];
|
||||
|
||||
# https://github.com/cachix/devenv/issues/528#issuecomment-1556108767
|
||||
containers = pkgs.lib.mkForce { };
|
||||
};
|
||||
|
||||
ci = devenv.shells.default;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
11
vendor/github.com/go-viper/mapstructure/v2/internal/errors/errors.go
generated
vendored
Normal file
11
vendor/github.com/go-viper/mapstructure/v2/internal/errors/errors.go
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
package errors
|
||||
|
||||
import "errors"
|
||||
|
||||
func New(text string) error {
|
||||
return errors.New(text)
|
||||
}
|
||||
|
||||
func As(err error, target interface{}) bool {
|
||||
return errors.As(err, target)
|
||||
}
|
||||
9
vendor/github.com/go-viper/mapstructure/v2/internal/errors/join.go
generated
vendored
Normal file
9
vendor/github.com/go-viper/mapstructure/v2/internal/errors/join.go
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
//go:build go1.20
|
||||
|
||||
package errors
|
||||
|
||||
import "errors"
|
||||
|
||||
func Join(errs ...error) error {
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
61
vendor/github.com/go-viper/mapstructure/v2/internal/errors/join_go1_19.go
generated
vendored
Normal file
61
vendor/github.com/go-viper/mapstructure/v2/internal/errors/join_go1_19.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
//go:build !go1.20
|
||||
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package errors
|
||||
|
||||
// Join returns an error that wraps the given errors.
|
||||
// Any nil error values are discarded.
|
||||
// Join returns nil if every value in errs is nil.
|
||||
// The error formats as the concatenation of the strings obtained
|
||||
// by calling the Error method of each element of errs, with a newline
|
||||
// between each string.
|
||||
//
|
||||
// A non-nil error returned by Join implements the Unwrap() []error method.
|
||||
func Join(errs ...error) error {
|
||||
n := 0
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
n++
|
||||
}
|
||||
}
|
||||
if n == 0 {
|
||||
return nil
|
||||
}
|
||||
e := &joinError{
|
||||
errs: make([]error, 0, n),
|
||||
}
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
e.errs = append(e.errs, err)
|
||||
}
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
type joinError struct {
|
||||
errs []error
|
||||
}
|
||||
|
||||
func (e *joinError) Error() string {
|
||||
// Since Join returns nil if every value in errs is nil,
|
||||
// e.errs cannot be empty.
|
||||
if len(e.errs) == 1 {
|
||||
return e.errs[0].Error()
|
||||
}
|
||||
|
||||
b := []byte(e.errs[0].Error())
|
||||
for _, err := range e.errs[1:] {
|
||||
b = append(b, '\n')
|
||||
b = append(b, err.Error()...)
|
||||
}
|
||||
// At this point, b has at least one byte '\n'.
|
||||
// return unsafe.String(&b[0], len(b))
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (e *joinError) Unwrap() []error {
|
||||
return e.errs
|
||||
}
|
||||
1712
vendor/github.com/go-viper/mapstructure/v2/mapstructure.go
generated
vendored
Normal file
1712
vendor/github.com/go-viper/mapstructure/v2/mapstructure.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
44
vendor/github.com/go-viper/mapstructure/v2/reflect_go1_19.go
generated
vendored
Normal file
44
vendor/github.com/go-viper/mapstructure/v2/reflect_go1_19.go
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
//go:build !go1.20
|
||||
|
||||
package mapstructure
|
||||
|
||||
import "reflect"
|
||||
|
||||
func isComparable(v reflect.Value) bool {
|
||||
k := v.Kind()
|
||||
switch k {
|
||||
case reflect.Invalid:
|
||||
return false
|
||||
|
||||
case reflect.Array:
|
||||
switch v.Type().Elem().Kind() {
|
||||
case reflect.Interface, reflect.Array, reflect.Struct:
|
||||
for i := 0; i < v.Type().Len(); i++ {
|
||||
// if !v.Index(i).Comparable() {
|
||||
if !isComparable(v.Index(i)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return v.Type().Comparable()
|
||||
|
||||
case reflect.Interface:
|
||||
// return v.Elem().Comparable()
|
||||
return isComparable(v.Elem())
|
||||
|
||||
case reflect.Struct:
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
return false
|
||||
|
||||
// if !v.Field(i).Comparable() {
|
||||
if !isComparable(v.Field(i)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
default:
|
||||
return v.Type().Comparable()
|
||||
}
|
||||
}
|
||||
10
vendor/github.com/go-viper/mapstructure/v2/reflect_go1_20.go
generated
vendored
Normal file
10
vendor/github.com/go-viper/mapstructure/v2/reflect_go1_20.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
//go:build go1.20
|
||||
|
||||
package mapstructure
|
||||
|
||||
import "reflect"
|
||||
|
||||
// TODO: remove once we drop support for Go <1.20
|
||||
func isComparable(v reflect.Value) bool {
|
||||
return v.Comparable()
|
||||
}
|
||||
Reference in New Issue
Block a user