Documentation ¶
Overview ¶
Package mapstructurex contains various extensions (primarily decoding hooks) to mapstructure.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapDecoderHookFunc ¶
func MapDecoderHookFunc() mapstructure.DecodeHookFunc
MapDecoderHookFunc returns a mapstructure.DecodeHookFunc that applies maps to the DecodeMap function, when the target type implements the MapDecoder interface.
Example ¶
var person Person decoder, _ := CreateDecoderWithMapDecoderHook(&person) input := map[string]any{ "name": "Bob", "age": 42, } _ = decoder.Decode(input) fmt.Println(person)
Output: Bob: 42
Example (Polymorphic) ¶
var config Config decoder, _ := CreateDecoderWithMapDecoderHook(&config) input := map[string]any{ "type": "baz", "config": map[string]any{ "baz": "bat", }, } err := decoder.Decode(input) if err != nil { panic(err) } fmt.Println(config.Foo())
Output: bat
Types ¶
type MapDecoder ¶
MapDecoder is the interface implemented by an object that can decode a raw map representation of itself.
Click to show internal directories.
Click to hide internal directories.