mapper

package
v0.0.0-...-26b1f7c Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2017 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

View Source
const (
	InvalidClass int = iota
	BoolClass
	IntClass
	UintClass
	FloatClass
	ComplexClass
	SliceClass
	ChanClass
	FuncClass
	InterfaceClass
	MapClass
	PtrClass
	StringClass
	StructClass
	UnsafePointerClass
)

Compatible type classes

View Source
const (
	Assignable int = iota
	Convertible
	Incompatible
)

Assignability

Variables

View Source
var (
	// StringType defined and used as a const
	StringType = reflect.TypeOf("")
	// InterfaceType defined and used as a const
	InterfaceType = reflect.TypeOf([]interface{}{}).Elem()
)

Functions

func IsContainer

func IsContainer(v reflect.Value) bool

IsContainer determine if the value is map or struct

func IsEmpty

func IsEmpty(v reflect.Value) bool

IsEmpty determine if the value is an empty value

func Map

func Map(v, s interface{}) error

Map wraps Mapper.Map with a default Mapper instance

func StringifyKeys

func StringifyKeys(val interface{}) interface{}

StringifyKeys converts keys to strings

func TypeClass

func TypeClass(kind reflect.Kind) int

TypeClass converts reflect.Kind to compatible class

func TypeCompatibility

func TypeCompatibility(from, to reflect.Type) int

TypeCompatibility determines the assignment/conversion compatibility

func UnwrapAny

func UnwrapAny(v reflect.Value) reflect.Value

UnwrapAny returns the actual value from interface/ptr

func UnwrapInterface

func UnwrapInterface(v reflect.Value) reflect.Value

UnwrapInterface returns the actual value of the interface

func UnwrapPtr

func UnwrapPtr(v reflect.Value) reflect.Value

UnwrapPtr returns the actual value pointed to

Types

type AutoDecoder

type AutoDecoder struct {
}

AutoDecoder selects the correct decoder by detecting the content

func (*AutoDecoder) Decode

func (d *AutoDecoder) Decode(content []byte) (out interface{}, err error)

Decode implements Decoder

type Decoder

type Decoder interface {
	Decode(content []byte) (interface{}, error)
}

Decoder defines the interface for parsing the content

type FieldInfo

type FieldInfo struct {
	Exported  bool
	Squash    bool
	OmitEmpty bool
	Wildcard  bool
	Ignore    bool
	MapName   string
}

FieldInfo contains parsed information from struct field

type JSONDecoder

type JSONDecoder struct {
}

JSONDecoder decodes content in JSON

func (*JSONDecoder) Decode

func (d *JSONDecoder) Decode(content []byte) (out interface{}, err error)

Decode implements Decoder

type Loader

type Loader struct {
	Map     map[string]interface{}
	Decoder Decoder
}

Loader loads and parses map from file/string

func (*Loader) As

func (l *Loader) As(out interface{}) error

As maps the decoded content into specific type

func (*Loader) LoadBytes

func (l *Loader) LoadBytes(content []byte) error

LoadBytes decodes the content in bytes

func (*Loader) LoadFile

func (l *Loader) LoadFile(fn string) error

LoadFile loads from a file or stdin if fn is empty or '-'

func (*Loader) LoadStream

func (l *Loader) LoadStream(s io.Reader) error

LoadStream loads from a stream

func (*Loader) LoadString

func (l *Loader) LoadString(content string) error

LoadString decodes the content in string

func (*Loader) Loaded

func (l *Loader) Loaded() bool

Loaded determines if content has been loaded

type MapTracer

type MapTracer func(d, s reflect.Value, loc string)

MapTracer receives the traversal in mapping

type Mapper

type Mapper struct {
	FieldTags []string
	Tracer    MapTracer
}

Mapper assign dynamic values

func (*Mapper) Map

func (m *Mapper) Map(v, s interface{}) error

Map assign values between interface{} types

func (*Mapper) MapValue

func (m *Mapper) MapValue(v, s reflect.Value) error

MapValue copies values of reflect.Value If the destination is a pointer, the address is assigned

func (*Mapper) ParseField

func (m *Mapper) ParseField(f reflect.StructField) *FieldInfo

ParseField extracts useful information from struct field

type TypeConverter

type TypeConverter func(reflect.Value) reflect.Value

TypeConverter defines the function to convert values IsValid is false if not convertible

func TypeConverterFactory

func TypeConverterFactory(from, to reflect.Type) TypeConverter

TypeConverterFactory creates the converter by types

type YAMLDecoder

type YAMLDecoder struct {
}

YAMLDecoder decodes content in YAML

func (*YAMLDecoder) Decode

func (d *YAMLDecoder) Decode(content []byte) (out interface{}, err error)

Decode implements Decoder

Jump to

Keyboard shortcuts

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