jinzhu / copier

Copier for golang, copy value from struct to struct and more
MIT License
5.58k stars 489 forks source link

能提供一个自定义字段映射的功能么 #87

Closed oneone1995 closed 3 years ago

oneone1995 commented 3 years ago

Describe the feature

有两个struct的属性字段名不同,但是含义却是相同的,例如:

type User struct {
    Name string
}

type UserVo struct{
    UserName string
}

Java中类似的库orika就提供了下面的处理方案。

    mapperFactory.classMap(PersonSource.class, PersonDestination.class)
       .field("firstName", "givenName")
       .field("lastName", "sirName")
       .byDefault()
       .register();

Motivation

这种场景还是比较常见的,希望能提供类似的功能支持

Related Issues

刚发现PR中前两天正好有人提了。 Copy different field name from tag flag #86

jinzhu commented 3 years ago

done.