Documentation
¶
Overview ¶
Package s2s maps structs to structs using reflection It does this in an opinionated way by default, but is configurable
Index ¶
- Variables
- func CaseInsensitiveMapper(s string) string
- func MapPtrToVal(v reflect.Value, t reflect.Type) interface{}
- func MapStruct(input interface{}, output interface{}) error
- func MapStructEx(cfg MapperConfig, input interface{}, output interface{}) error
- type MapperConfig
- type NameMapper
- type ValueMapper
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = MapperConfig{ NameMapper: nil, ValueMapper: nil, SkipMissingField: true, SkipFailedConversion: true, MapNilToZeroImplicit: true, }
var ErrArgumentsInvalid = errors.New("input or output argument not pointer to struct")
var ErrInvalidConversion = errors.New("ValueMapper return can't be assigned to targetType")
var ErrMissingField = errors.New("Destination struct is missing field")
Functions ¶
func CaseInsensitiveMapper ¶
Mapper that ignores capitalization in names
func MapPtrToVal ¶
Mapper that maps pointer types to direct types *T -> T using Zero(T) for nil
func MapStruct ¶
func MapStruct(input interface{}, output interface{}) error
MapStruct takes a pointer to an input struct and a pointer to an output struct. It will perform a mapping using the default options
func MapStructEx ¶
func MapStructEx(cfg MapperConfig, input interface{}, output interface{}) error
MapStructEx takes an additional argument compared to MapStruct for configuration.
Types ¶
type MapperConfig ¶
type MapperConfig struct { // This function if set will be called every time a field name is used // allowing you to map handle conversions like CamelCase -> snake_case NameMapper NameMapper // This function if set will be called when mapping an input value // to an output fields type. // For convenience you are allowed to return both a value directly or // behind a pointer. // Also if `MapNilToZeroImplicit` is set (default), returned typed nil // pointers will be implicitly mapped to the zero value if the output // field is not of pointer type ValueMapper ValueMapper // If set (default) the mapper will not error on fields that can't be // mapped to an output field SkipMissingField bool // If set (default) the mapper will not error if a conversion from input // field type to output field type fails SkipFailedConversion bool // If set (default) the mapper will implicitly convert typed nil pointers // to zero values of the type as needed MapNilToZeroImplicit bool }
type NameMapper ¶
Maps field names to allow flexibility in mapping
type ValueMapper ¶
Expected to map `value` to a value of either `targetType` or `*targetType` Can be chained using CompositeMapper
func CompositeMapper ¶
func CompositeMapper(mappers ...ValueMapper) ValueMapper
Used to chain together multiple ValueMapper in the given order