golang struct/结构复制

更新日期:2021-4-7结论:试试 copier 改进。 mergo 库(github.com/imdario/mergo)https://darjun.github.io/2020/03/11/godailylib/mergo/用来给结构体或map赋值的,不足只能处理相同的类型的结构,如果类型...

更新日期:2021-4-7

结论:试试 copier 改进。

 

mergo 库

(github.com/imdario/mergo)

https://darjun.github.io/2020/03/11/godailylib/mergo/

用来给结构体或map赋值的,不足只能处理相同的类型的结构,如果类型不同,即使字段名和类型完全相同,也不可以。

 

copier 库

github.com/jinzhu/copier

可以处理不同类型的结构赋值

https://zhuanlan.zhihu.com/p/113301827

 

copier 改进

https://github.com/ybzhanghx/copier

通过指定 tag 实现不同类型的结构之间的复制

改进结构中的类型转化

 

如以上的二个结构间的复制。

支持深拷贝

 

https://zhuanlan.zhihu.com/p/265510742?utm_source=qq

 

本文标题为:golang struct/结构复制

基础教程推荐