自定义的结构体标签在编辑器中不生效,键入缩写不提示实时模版,就和没有定义一样,有没有大佬知道这个怎么解决?
你还可以尝试用 Gozz
对结构体标签进行模板化的管理 所有标签通过注解自动化模板化管理
比如:
package tag01
import (
"time"
)
//go:generate gozz run -p "tag" ./
// +zz:tag:json,bson:{{ snake .FieldName }}
type User struct {
Id string `bson:"id" json:"id"`
Name string `bson:"name" json:"name"`
Address string `bson:"address" json:"address"`
CreatedAt time.Time `bson:"created_at" json:"created_at"`
UpdatedAt time.Time `bson:"updated_at" json:"updated_at"`
}
再比如
// +zz:tag:json,bson:{{ snake .FieldName }}
type (
User struct {
Id string `bson:"id" json:"id"`
Name string `bson:"name" json:"name"`
Address string `bson:"address" json:"address"`
CreatedAt time.Time `bson:"created_at" json:"created_at"`
UpdatedAt time.Time `bson:"updated_at" json:"updated_at"`
}
// +zz:tag:json,bson:{{ camel .FieldName }}
Book struct {
Id string `bson:"id" json:"id"`
Title string `bson:"title" json:"title"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
}
Order struct {
Id string `bson:"id" json:"id"`
UserId string `bson:"user_id" json:"user_id"`
BookId string `bson:"book_id" json:"book_id"`
// +zz:tag:json,bson:{{ snake .FieldName | upper }}
CreatedAt time.Time `bson:"CREATED_AT" json:"CREATED_AT"`
// +zz:tag:+json:,omitempty
UpdatedAt time.Time `bson:"updated_at" json:"updated_at,omitempty"`
}
)
7 回答5.3k 阅读
6 回答6.9k 阅读✓ 已解决
4 回答2.3k 阅读
1 回答2k 阅读✓ 已解决
1 回答3.4k 阅读
2 回答2.2k 阅读
1 回答2.1k 阅读
适用于Go: 标记.
下面有个更改按钮,点开,然后把Go下面的那些复选框都勾上即可。