copier
copier copied to clipboard
custom type convert rules
Describe the feature
Custom type conversion rules to allow different types of conversion example:
type User struct {
CreateAt time.Time
BirthDay time.Time
}
type Person struct {
CreateAt uint64
BirthDay string
}
func TestTimeToString(t *testing.T) {
RegisterConverter(reflect.TypeOf(""), reflect.TypeOf(time.Time{}), func(v interface{}) interface{} {
t := v.(time.Time)
return t.Format(time.RFC3339)
})
from := &User{
BirthDay: time.Unix(123456, 0),
}
to := &Person{}
Copy(to, from)
if to.BirthDay != "1970-01-02T18:17:36+08:00" {
t.Error("time to string copy failed")
}
}
Motivation
Related Issues
hey @fuguohong, the PR #115 was merged today :partying_face:. With it, you can make these kinds of type conversions via a converter option. Have a look into the PR for an example. cheers tom
Seems to be address by #115