说明
- 不同大类,如json和gorm标签之前用空格分隔
- 在gorm标签中,不同的标签使用;分隔
- 在json中,标签之间用,分隔
type Api struct {
// 不同大类之间用空格分隔,如json和gorm标签之前用空格分隔
// 同一类型gorm不同的标签使用;分隔,如comment(字段注释)和index(索引,索引名字:idx_id)标签
Id int `json:"id" gorm:"comment:api id;index:idx_id"`
}
json
序列化时使用
type Product struct {
Name string `json:"name"`
// omitempty在序列化的时候忽略0值或者空值
ProductID int64 `json:"product_id,omitempty"`
// 额外支持string类型,json此字段为string时也可匹配
Number int `json:"number,string"`
}
gorm
https://blog.youkuaiyun.com/xuemeilu/article/details/124871919
form
type PageInfo struct {
Page int `json:"page" form:"page"` // 页码
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
}
mapstructure
yaml
type Zap struct {
Level string `mapstructure:"level" json:"level" yaml:"level"` // 级别
Format string `mapstructure:"format" json:"format" yaml:"format"` // 输出
}