(target any, key string, settings map[string]any)
| 115 | } |
| 116 | |
| 117 | func decodeKey(target any, key string, settings map[string]any) error { |
| 118 | nodes := strings.SplitSeq(key, ".") |
| 119 | |
| 120 | for node := range nodes { |
| 121 | v := settings[node] |
| 122 | |
| 123 | if v == nil { |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | if m, ok := v.(map[string]any); ok { |
| 128 | settings = m |
| 129 | } else { |
| 130 | return fmt.Errorf("unable to find node %s", node) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | c := mapstructure.DecoderConfig{ |
| 135 | Result: target, |
| 136 | WeaklyTypedInput: true, |
| 137 | DecodeHook: mapstructure.ComposeDecodeHookFunc( |
| 138 | mapstructure.StringToIPNetHookFunc(), |
| 139 | mapstructure.StringToTimeDurationHookFunc(), |
| 140 | stringToSliceHookFunc(','), |
| 141 | ), |
| 142 | } |
| 143 | |
| 144 | decoder, err := mapstructure.NewDecoder(&c) |
| 145 | if err != nil { |
| 146 | return err |
| 147 | } |
| 148 | |
| 149 | err = decoder.Decode(settings) |
| 150 | if err != nil { |
| 151 | return err |
| 152 | } |
| 153 | |
| 154 | return nil |
| 155 | } |
| 156 | |
| 157 | func decode(target any, v *viper.Viper) func(*cobra.Command, []string) error { |
| 158 | return func(cmd *cobra.Command, args []string) error { |
no test coverage detected