Documentation
¶
Overview ¶
Package hooks provides mapstructure decode hooks for use with DcValue[T] fields. When decoding YAML or map[string]any data into structs containing DcValue[T] fields, use MapstructureHookFunc() so that mapstructure automatically constructs properly-typed DcValue instances.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapstructureHookFunc ¶
func MapstructureHookFunc() mapstructure.DecodeHookFunc
MapstructureHookFunc returns a mapstructure.DecodeHookFunc that detects target fields of type *poya.DcValue[T] and initializes them from the decoded source data.
For scalar T types (string, int, bool, etc.), the source value is set directly. For struct T types, the source value (typically map[string]any from YAML decoding) is JSON-marshaled and then set via InternalSetJSON.
Usage:
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
DecodeHook: hooks.MapstructureHookFunc(),
Result: &cfg,
})
if err != nil { ... }
err = decoder.Decode(viper.AllSettings())
func MapstructureHookFuncValue ¶
func MapstructureHookFuncValue() mapstructure.DecodeHookFuncValue
MapstructureHookFuncValue returns a mapstructure.DecodeHookFuncValue for use with ComposeDecodeHookFunc or when the value hook type is needed.
Types ¶
This section is empty.