Documentation
¶
Index ¶
- Constants
- Variables
- func Copy(toValue interface{}, fromValue interface{}, options ...OptionFunc) (err error)
- func CopyCase(toValue interface{}, fromValue interface{}) (err error)
- func CopyCaseDeep(toValue interface{}, fromValue interface{}) (err error)
- func CopyDeep(toValue interface{}, fromValue interface{}) (err error)
- func CopyWithOption(toValue interface{}, fromValue interface{}, opt Option) (err error)
- type FieldNameMapping
- type Option
- type OptionFunc
- type TypeConverter
Constants ¶
View Source
const ( // Some default converter types for a nicer syntax String string = "" Bool bool = false Int int = 0 Float32 float32 = 0 Float64 float64 = 0 )
These flags define options for tag handling
Variables ¶
View Source
var ( ErrInvalidCopyDestination = errors.New("copy destination must be non-nil and addressable") ErrInvalidCopyFrom = errors.New("copy from must be non-nil and addressable") ErrMapKeyNotMatch = errors.New("map's key type doesn't match") ErrNotSupported = errors.New("not supported") ErrFieldNameTagStartNotUpperCase = errors.New("copier field name tag must be start upper case") )
Functions ¶
func Copy ¶
func Copy(toValue interface{}, fromValue interface{}, options ...OptionFunc) (err error)
Copy copy things
func CopyCase ¶
func CopyCase(toValue interface{}, fromValue interface{}) (err error)
CopyCase copy things with case sensitive
func CopyCaseDeep ¶
func CopyCaseDeep(toValue interface{}, fromValue interface{}) (err error)
CopyCaseDeep copy things with case sensitive and deep copy
func CopyDeep ¶
func CopyDeep(toValue interface{}, fromValue interface{}) (err error)
CopyDeep copy things with deep copy
func CopyWithOption ¶
CopyWithOption copy with option
Types ¶
type FieldNameMapping ¶
type Option ¶
type Option struct {
// setting this value to true will ignore copying zero values of all the fields, including bools, as well as a
// struct having all it's fields set to their zero values respectively (see IsZero() in reflect/value.go)
IgnoreEmpty bool
CaseSensitive bool
DeepCopy bool
Converters []TypeConverter
// Custom field name mappings to copy values with different names in `fromValue` and `toValue` types.
// Examples can be found in `copier_field_name_mapping_test.go`.
FieldNameMapping []FieldNameMapping
TimeLayout string //time string layout
}
Option sets copy options
type OptionFunc ¶
type OptionFunc func(opt *Option)
func WithCaseSensitive ¶
func WithCaseSensitive() OptionFunc
func WithConverters ¶
func WithConverters(converters []TypeConverter) OptionFunc
func WithDeepCopy ¶
func WithDeepCopy() OptionFunc
func WithFieldNameMapping ¶
func WithFieldNameMapping(fieldNameMapping []FieldNameMapping) OptionFunc
func WithIgnoreEmpty ¶
func WithIgnoreEmpty() OptionFunc
func WithTimeLayout ¶
func WithTimeLayout(layout string) OptionFunc
type TypeConverter ¶
type TypeConverter struct {
SrcType interface{}
DstType interface{}
Fn func(src interface{}) (dst interface{}, err error)
}
Click to show internal directories.
Click to hide internal directories.