-
Notifications
You must be signed in to change notification settings - Fork 497
Closed
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels