72
72
// "name": "alice",
73
73
// }
74
74
//
75
+ // When decoding from a struct to a map, the squash tag squashes the struct
76
+ // fields into a single map. Using the example structs from above:
77
+ //
78
+ // Friend{Person: Person{Name: "alice"}}
79
+ //
80
+ // Will be decoded into a map:
81
+ //
82
+ // map[string]interface{}{
83
+ // "name": "alice",
84
+ // }
85
+ //
75
86
// DecoderConfig has a field that changes the behavior of mapstructure
76
87
// to always squash embedded structs.
77
88
//
@@ -161,10 +172,11 @@ import (
161
172
// data transformations. See "DecodeHook" in the DecoderConfig
162
173
// struct.
163
174
//
164
- // The type should be DecodeHookFuncType or DecodeHookFuncKind.
165
- // Either is accepted. Types are a superset of Kinds (Types can return
166
- // Kinds) and are generally a richer thing to use, but Kinds are simpler
167
- // if you only need those.
175
+ // The type must be one of DecodeHookFuncType, DecodeHookFuncKind, or
176
+ // DecodeHookFuncValue.
177
+ // Values are a superset of Types (Values can return types), and Types are a
178
+ // superset of Kinds (Types can return Kinds) and are generally a richer thing
179
+ // to use, but Kinds are simpler if you only need those.
168
180
//
169
181
// The reason DecodeHookFunc is multi-typed is for backwards compatibility:
170
182
// we started with Kinds and then realized Types were the better solution,
@@ -189,10 +201,13 @@ type DecodeHookFuncValue func(from reflect.Value, to reflect.Value) (interface{}
189
201
type DecoderConfig struct {
190
202
// DecodeHook, if set, will be called before any decoding and any
191
203
// type conversion (if WeaklyTypedInput is on). This lets you modify
192
- // the values before they're set down onto the resulting struct.
204
+ // the values before they're set down onto the resulting struct. The
205
+ // DecodeHook is called for every map and value in the input. This means
206
+ // that if a struct has embedded fields with squash tags the decode hook
207
+ // is called only once with all of the input data, not once for each
208
+ // embedded struct.
193
209
//
194
- // If an error is returned, the entire decode will fail with that
195
- // error.
210
+ // If an error is returned, the entire decode will fail with that error.
196
211
DecodeHook DecodeHookFunc
197
212
198
213
// If ErrorUnused is true, then it is an error for there to exist
0 commit comments