gtag is a command tool that can automatically generate tags for golang struct.
Quick start
Install gtag into your GOPATH
go install github.com/sycki/gtag@latest
Batch process your files
gtag -a json:camel,yaml:camel,form:camel,gorm:snake model/*.go
File content
type User struct {
Name string `json:"name" yaml:"name" gorm:"name"`
IdCard string `json:"idCard" yaml:"idCard" gorm:"id_card"`
ResidentialAddress string `json:"residentialAddress" yaml:"residentialAddress" gorm:"residential_address"`
CompanyName string `json:"companyName" yaml:"companyName" gorm:"company_name"`
}
Usage
gtag is a command tool that can automatically generate tags for golang struct.
Usage: gtag [OPTIONS] filename ...
Options:
-a, --add <tagName:style>
Add tags to struct, tagName can be any string,
style effective value: camel, snake, go, upper, lower.
-r, --remove <tagName>
Remove tags from struct, tagName can be any string.
-i, --index <number>
Specify the position for the --add option,
-1 means cover all, 0 means insert to the front.
Examples:
gtag -a yaml:camel -a gorm:snake model/*.go
gtag -a yaml:camel,gorm:snake -i -1 -r json model/*.go