MCPcopy Create free account
hub / github.com/apache/camel-k / decodeKey

Function decodeKey

pkg/cmd/util.go:117–155  ·  view source on GitHub ↗
(target any, key string, settings map[string]any)

Source from the content-addressed store, hash-verified

115}
116
117func 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
157func decode(target any, v *viper.Viper) func(*cobra.Command, []string) error {
158 return func(cmd *cobra.Command, args []string) error {

Callers 2

decodeMethod · 0.85
decodeFunction · 0.85

Calls 2

stringToSliceHookFuncFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected