mapping

package
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT Imports: 16 Imported by: 141

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deref

func Deref(t reflect.Type) reflect.Type

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

func Marshal added in v1.3.3

func Marshal(val any) (map[string]map[string]any, 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 commonly used.

func Repr

func Repr(v any) string

Repr returns the string representation of v.

func SetMapIndexValue added in v1.4.4

func SetMapIndexValue(tp reflect.Type, value, key, target reflect.Value)

SetMapIndexValue sets target to value at key position, pointers are processed automatically.

func SetValue added in v1.4.4

func SetValue(tp reflect.Type, value, target reflect.Value)

SetValue sets target to value, pointers are processed automatically.

func UnmarshalJsonBytes

func UnmarshalJsonBytes(content []byte, v any, opts ...UnmarshalOption) error

UnmarshalJsonBytes unmarshals content into v.

func UnmarshalJsonMap

func UnmarshalJsonMap(m map[string]any, v any, opts ...UnmarshalOption) error

UnmarshalJsonMap unmarshals content from m into v.

func UnmarshalJsonReader

func UnmarshalJsonReader(reader io.Reader, v any, opts ...UnmarshalOption) error

UnmarshalJsonReader unmarshals content from reader into v.

func UnmarshalKey

func UnmarshalKey(m map[string]any, v any) error

UnmarshalKey unmarshals m into v with the tag key.

func UnmarshalTomlBytes added in v1.3.4

func UnmarshalTomlBytes(content []byte, v any, opts ...UnmarshalOption) error

UnmarshalTomlBytes unmarshals TOML bytes into the given v.

func UnmarshalTomlReader added in v1.3.4

func UnmarshalTomlReader(r io.Reader, v any, opts ...UnmarshalOption) error

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

func UnmarshalYamlBytes

func UnmarshalYamlBytes(content []byte, v any, opts ...UnmarshalOption) error

UnmarshalYamlBytes unmarshals content into v.

func UnmarshalYamlReader

func UnmarshalYamlReader(reader io.Reader, v any, opts ...UnmarshalOption) 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 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 WithDefault added in v1.4.5

func WithDefault() UnmarshalOption

WithDefault customizes an Unmarshaler with fill default values.

func WithOpaqueKeys added in v1.5.5

func WithOpaqueKeys() UnmarshalOption

WithOpaqueKeys customizes an Unmarshaler with opaque keys. Opaque keys are keys that are not processed by the unmarshaler.

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 the given tag key.

func NewUnmarshaler

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

NewUnmarshaler returns an Unmarshaler.

func (*Unmarshaler) Unmarshal

func (u *Unmarshaler) Unmarshal(i, v any) error

Unmarshal unmarshals m into v.

func (*Unmarshaler) UnmarshalValuer

func (u *Unmarshaler) UnmarshalValuer(m Valuer, v any) error

UnmarshalValuer unmarshals m into v.

type Valuer

type Valuer interface {
	// Value gets the value associated with the given key.
	Value(key string) (any, 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