mapstructure

package
v1.300045.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(rawVal any) (map[string]any, error)

func MarshalerHookFunc

func MarshalerHookFunc(orig any) mapstructure.DecodeHookFuncValue

MarshalerHookFunc returns a DecodeHookFuncValue that checks structs that aren't the original to see if they implement the Marshaler interface.

func NilHookFunc

func NilHookFunc[T any]() mapstructure.DecodeHookFuncValue

NilHookFunc returns a DecodeHookFuncValue that checks if the value matches the type and nils it out. Allows specific types to be omitted.

func NilZeroValueHookFunc

func NilZeroValueHookFunc[T any]() mapstructure.DecodeHookFuncValue

NilZeroValueHookFunc returns a DecodeHookFuncValue that only nils the field if it's a zero value.

func TextMarshalerHookFunc

func TextMarshalerHookFunc() mapstructure.DecodeHookFuncValue

TextMarshalerHookFunc returns a DecodeHookFuncValue that checks for the encoding.TextMarshaler interface and calls the MarshalText function if found.

func UnsupportedKindHookFunc

func UnsupportedKindHookFunc() mapstructure.DecodeHookFuncValue

UnsupportedKindHookFunc returns a DecodeHookFuncValue that checks that the kind isn't one unsupported by the YAML encoder.

Types

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

An Encoder takes structured data and converts it into an interface following the mapstructure tags.

func New

func New(cfg *EncoderConfig) *Encoder

New returns a new encoder for the configuration.

func (*Encoder) Encode

func (e *Encoder) Encode(input any) (any, error)

Encode takes the input and uses reflection to encode it to an interface based on the mapstructure spec.

type EncoderConfig

type EncoderConfig struct {
	// EncodeHook, if set, is a way to provide custom encoding. It
	// will be called before structs and primitive types.
	EncodeHook mapstructure.DecodeHookFunc
	// NilEmptyMap, if set, is a way to nil out empty maps.
	NilEmptyMap bool
	// OmitNilFields, if set, is a way to omit all nil struct fields even if omitempty isn't present.
	OmitNilFields bool
}

EncoderConfig is the configuration used to create a new encoder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL