WeakDecode is similar to mapstructure.WeakDecode, but it also supports decoding RFC3339Nano-formatted timestamp strings to time.Time.
(input, output any)
| 8 | |
| 9 | // WeakDecode is similar to mapstructure.WeakDecode, but it also supports decoding RFC3339Nano-formatted timestamp strings to time.Time. |
| 10 | func WeakDecode(input, output any) error { |
| 11 | config := &mapstructure.DecoderConfig{ |
| 12 | DecodeHook: mapstructure.StringToTimeHookFunc(time.RFC3339Nano), |
| 13 | Metadata: nil, |
| 14 | Result: output, |
| 15 | WeaklyTypedInput: true, |
| 16 | } |
| 17 | |
| 18 | decoder, err := mapstructure.NewDecoder(config) |
| 19 | if err != nil { |
| 20 | return err |
| 21 | } |
| 22 | |
| 23 | return decoder.Decode(input) |
| 24 | } |
| 25 | |
| 26 | // WeakDecodeWithWarnings is like WeakDecode but also returns any unused keys from the input. |
| 27 | func WeakDecodeWithWarnings(input, output any) ([]string, error) { |