Documentation ¶
Index ¶
- func NewDecoder(output any, opts ...Option) encodingx.Decoder
- func Unmarshal(input, output any, opts ...Option) error
- type Option
- func DecodeHookFuncKinds(fs ...func(reflect.Kind, reflect.Kind, any) (any, error)) Option
- func DecodeHookFuncTypes(fs ...func(reflect.Type, reflect.Type, any) (any, error)) Option
- func DecodeHookFuncValues(fs ...mapstructure.DecodeHookFuncValue) Option
- func ErrorUnset() Option
- func ErrorUnused() Option
- func IgnoreUntaggedFields() Option
- func MatchName(f func(mapKey, fieldName string) bool) Option
- func Metadata(md *mapstructure.Metadata) Option
- func RecursiveStructToMap() Option
- func Squash() Option
- func StringToIP() Option
- func StringToIPNet() Option
- func StringToSlice(separators ...string) Option
- func StringToTimeDuration() Option
- func StringToTimeTime(layout string) Option
- func TagName(name string) Option
- func TextUnmarshaller() Option
- func WeaklyTyped() Option
- func WeaklyTypedInput() Option
- func ZeroFields() Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDecoder ¶
NewDecoder returns a new decoder.
Types ¶
type Option ¶
type Option func(*options)
func DecodeHookFuncKinds ¶
DecodeHookFuncKinds is a DecodeHookFunc which knows only the Kinds of the source and target types.
func DecodeHookFuncTypes ¶
DecodeHookFuncTypes is a DecodeHookFunc which has complete information about the source and target types.
func DecodeHookFuncValues ¶
func DecodeHookFuncValues(fs ...mapstructure.DecodeHookFuncValue) Option
DecodeHookFuncValues is a DecodeHookFunc which has complete access to both the source and target values.
func ErrorUnset ¶
func ErrorUnset() Option
ErrorUnset If set to true, then it is an error for there to exist fields in the result that were not set in the decoding process (extra fields). This only applies to decoding to a struct. This will affect all nested structs as well.
func ErrorUnused ¶
func ErrorUnused() Option
ErrorUnused If set to true, then it is an error for there to exist keys in the original map that were unused in the decoding process (extra keys).
func IgnoreUntaggedFields ¶
func IgnoreUntaggedFields() Option
IgnoreUntaggedFields ignores all struct fields without explicit TagName, comparable to `mapstructure:"-"` as default behaviour.
func MatchName ¶
MatchName is the function used to match the map key to the struct field name or tag. Defaults to `strings.EqualFold`. This can be used to implement case-sensitive tag values, support snake casing, etc.
func Metadata ¶
func Metadata(md *mapstructure.Metadata) Option
Metadata is the struct that will contain extra metadata about the decoding. If this is nil, then no metadata will be tracked.
func RecursiveStructToMap ¶
func RecursiveStructToMap() Option
func Squash ¶
func Squash() Option
Squash will squash embedded structs. A squash tag may also be added to an individual struct field using a tag. For example:
type Parent struct { Child `mapstructure:",squash"` }
func StringToSlice ¶
StringToSlice converts string to []string by splitting on the given sep.
func StringToTimeDuration ¶
func StringToTimeDuration() Option
StringToTimeDuration converts strings to time.Duration.
func StringToTimeTime ¶
StringToTimeTime converts strings to time.Time.
func TagName ¶
TagName the tag name that mapstructure reads for field names. This defaults to "mapstructure"
func TextUnmarshaller ¶
func TextUnmarshaller() Option
TextUnmarshaller that applies strings to the UnmarshalText function, when the target type implements the encoding.TextUnmarshaler interface
func WeaklyTyped ¶
func WeaklyTyped() Option
func WeaklyTypedInput ¶
func WeaklyTypedInput() Option
WeaklyTypedInput if set to true, the decoder will make the following "weak" conversions:
- bools to string (true = "1", false = "0")
- numbers to string (base 10)
- bools to int/uint (true = 1, false = 0)
- strings to int/uint (base implied by prefix)
- int to bool (true if value != 0)
- string to bool (accepts: 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Anything else is an error)
- empty array = empty map and vice versa
- negative numbers to overflowed uint values (base 10)
- slice of maps to a merged map
- single values are converted to slices if required. Each element is weakly decoded. For example: "4" can become []int{4} if the target type is an int slice.
func ZeroFields ¶
func ZeroFields() Option
ZeroFields if set to true, will zero fields before writing them. For example, a map will be emptied before decoded values are put in it. If this is false, a map will be merged.