mapping

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedType is an error that indicates the config format is not supported.
	ErrUnsupportedType = errors.New("only map-like configs are supported")
)

Functions

func Deref

func Deref(t reflect.Type) reflect.Type

Deref dereferences a type, if pointer type, returns its element type.

func Marshal

func Marshal(val interface{}) (map[string]map[string]interface{}, error)

Marshal marshals the given val and returns the map that contains the fields. optional=another is not implemented, and it's hard to implement and not common used.

func Repr

func Repr(v interface{}) string

Repr returns the string representation of v.

func UnmarshalJsonBytes

func UnmarshalJsonBytes(content []byte, v interface{}) error

UnmarshalJsonBytes unmarshals content into v.

func UnmarshalJsonMap

func UnmarshalJsonMap(m map[string]interface{}, v interface{}) error

UnmarshalJsonMap unmarshals content from m into v.

func UnmarshalJsonReader

func UnmarshalJsonReader(reader io.Reader, v interface{}) error

UnmarshalJsonReader unmarshals content from reader into v.

func UnmarshalKey

func UnmarshalKey(m map[string]interface{}, v interface{}) error

UnmarshalKey unmarshals m into v with tag key.

func UnmarshalTomlBytes

func UnmarshalTomlBytes(content []byte, v interface{}) error

UnmarshalTomlBytes unmarshals TOML bytes into the given v.

func UnmarshalTomlReader

func UnmarshalTomlReader(r io.Reader, v interface{}) error

UnmarshalTomlReader unmarshals TOML from the given io.Reader into the given v.

func UnmarshalYamlBytes

func UnmarshalYamlBytes(content []byte, v interface{}) error

UnmarshalYamlBytes unmarshals content into v.

func UnmarshalYamlReader

func UnmarshalYamlReader(reader io.Reader, v interface{}) error

UnmarshalYamlReader unmarshals content from reader into v.

func ValidatePtr

func ValidatePtr(v *reflect.Value) error

ValidatePtr validates v if it's a valid pointer.

Types

type MapValuer

type MapValuer map[string]interface{}

A MapValuer is a map that can use Value method to get values with given keys.

func (MapValuer) Value

func (mv MapValuer) Value(key string) (interface{}, bool)

Value gets the value associated with the given key from mv.

type UnmarshalOption

type UnmarshalOption func(*unmarshalOptions)

UnmarshalOption defines the method to customize an Unmarshaler.

func WithCanonicalKeyFunc

func WithCanonicalKeyFunc(f func(string) string) UnmarshalOption

WithCanonicalKeyFunc customizes an Unmarshaler with Canonical Key func

func WithStringValues

func WithStringValues() UnmarshalOption

WithStringValues customizes an Unmarshaler with number values from strings.

type Unmarshaler

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

Unmarshaler is used to unmarshal with given tag key.

func NewUnmarshaler

func NewUnmarshaler(key string, opts ...UnmarshalOption) *Unmarshaler

NewUnmarshaler returns an Unmarshaler.

func (*Unmarshaler) Unmarshal

func (u *Unmarshaler) Unmarshal(m map[string]interface{}, v interface{}) error

Unmarshal unmarshals m into v.

func (*Unmarshaler) UnmarshalValuer

func (u *Unmarshaler) UnmarshalValuer(m Valuer, v interface{}) error

UnmarshalValuer unmarshals m into v.

type Valuer

type Valuer interface {
	// Value gets the value associated with the given key.
	Value(key string) (interface{}, bool)
}

A Valuer interface defines the way to get values from the underlying object with keys.

Jump to

Keyboard shortcuts

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