u
This commit is contained in:
@@ -11,15 +11,17 @@ type tagt uint8
|
||||
const (
|
||||
tagMust tagt = 1 << iota
|
||||
tagIgnore
|
||||
tagToName
|
||||
tagName
|
||||
tagFormat
|
||||
)
|
||||
|
||||
// 标签 copier 取值 must、ignore、toname 等
|
||||
// copier:"must,toname=xxx" 必须复制,并重命名为 xxx
|
||||
// copier:"must,name=xxx" 必须复制,并重命名为 xxx
|
||||
|
||||
type tagOption struct {
|
||||
flg tagt
|
||||
toname string
|
||||
name string
|
||||
format string
|
||||
}
|
||||
|
||||
func parseTag(tag string) *tagOption {
|
||||
@@ -28,15 +30,22 @@ func parseTag(tag string) *tagOption {
|
||||
flg := tagt(0)
|
||||
for t := range strings.SplitSeq(tag, ",") {
|
||||
tag, value, found := strings.Cut(t, "=")
|
||||
switch tag {
|
||||
lower := strings.ToLower(tag)
|
||||
|
||||
switch lower {
|
||||
case "-", "ignore":
|
||||
flg |= tagIgnore
|
||||
case "must":
|
||||
flg |= tagMust
|
||||
case "toname":
|
||||
flg |= tagToName
|
||||
case "name":
|
||||
flg |= tagName
|
||||
if found {
|
||||
opt.toname = value
|
||||
opt.name = value
|
||||
}
|
||||
case "format":
|
||||
flg |= tagFormat
|
||||
if found {
|
||||
opt.format = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user