安装:
go get github.com/fatih/gomodifytags
添加tag命令
gomodifytags -file demo.go -struct Server -add-tags json,xml -w -transform camelcase --skip-unexported
-file
哪个文件struct
指定哪个struct,否则是这个文件的所有structadd-tags
哪种文件的tag,如果是多个,则中间用逗号隔开w
将结果同步到这个文件transform
tag哪种形式- snakecase: “BaseDomain” -> “base_domain”
- camelcase: “BaseDomain” -> “baseDomain”
- lispcase: “BaseDomain” -> “base-domain”
- pascalcase: “BaseDomain” -> “BaseDomain”
- titlecase: “BaseDomain” -> “Base Domain”
- keep: keeps the original field name
skip-unexported
跳过未导出的字段
删除tag
gomodifytags -file demo.go -line 8,11 -clear-tags xml
https://github.com/fatih/gomodifytags