Categorygithub.com/uber-go/mapdecode
modulepackage
1.0.0
Repository: https://github.com/uber-go/mapdecode.git
Documentation: pkg.go.dev

# README

mapdecode GoDoc Build Status Coverage Status

mapdecode implements a generic interface{} decoder. It allows implementing custom YAML/JSON decoding logic only once. Instead of implementing the same UnmarshalYAML and UnmarshalJSON twice, you can implement Decode once, parse the YAML/JSON input into a map[string]interface{} and decode it using this package.

var data map[string]interface{}
if err := json.Decode(&data, input); err != nil {
    log.Fatal(err)
}

var result MyStruct
if err := mapdecode.Decode(&result, data); err != nil {
    log.Fatal(err)
}

This package relies heavily on mapstructure for much of its functionality.

Status

Stable: No breaking changes will be made before 2.0.


Released under the MIT License.

# Functions

Decode from src into dest where dest is a pointer to the value being decoded.
DecodeHook registers a hook to be called before a value is decoded by the system.
FieldHook registers a hook to be called when a struct field is being decoded by the system.
IgnoreUnused specifies whether we should ignore unused attributes in YAML.
TagName changes the name of the struct tag under which field names are expected.
YAML may be specified to decode go-yaml (gopkg.in/yaml.v2) compatible types.

# Interfaces

Decoder is any type which has custom decoding logic.

# Type aliases

DecodeHookFunc is a hook called before decoding a value into a specific type.
FieldHookFunc is a hook called while decoding a specific struct field.
Into is a function that attempts to decode the source data into the given shape.
Option customizes the behavior of Decode.