Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotSameType = errors.New("Dst and Src are not the same type") ErrSrcNil = errors.New("Input src type is nil") ErrDstNil = errors.New("Input dst type is nil") ErrDstNotPtr = errors.New("Input dst must be pointer") ErrSrcNotStruct = errors.New("Input src must be struct") ErrCannotSetField = errors.New("Field not addressable and/or cannot be set") )
Error types of package overwrite
var ( // ErrTagValueWrong values for wrong tag values ErrTagValueWrong = errors.New("Wrong tag value") )
Functions ¶
func Do ¶
func Do(dst, src interface{}) error
Do copies tagged fields of arguments <src> into <dst>
dst needs to be a pointer to same type of struct that src is src needs to be passed as value and not a pointer
Do traverses the value src recursively. If an encountered field is tagged with overwrite: true it tries to copy the value of that field into the dst counterpart field.
Supported types Simple types (string, intX, uintX, floatX, boolean) Arrays, slices, maps of simple types Structs with simple supported types (recursively) Pointers are not supported atm
The "omitempty" option specifies that the field should be omitted from the overwrite if the field has an empty value, defined as false, 0, and any empty array, slice, map, or string.
Examples of struct field tags and their meanings:
// Field in dst will be overwritten by the value in src Field int `overwrite:"true"` // Field in dst will be overwritten by the value in src // the field is omitted from the overwrite if its src value is empty, // as defined above. Field int `overwrite:"true,omitempty"` // Field will not be overwritten, same as not setting tag Field int `overwrite:"false"`
Channel, complex, and function values cannot be overwritten. Attempting to overwrite such a value will be silently ignored.
Types ¶
This section is empty.