This commit is contained in:
2025-09-30 18:41:21 +08:00
parent 2b90888901
commit 362dc000b1
7 changed files with 344 additions and 79 deletions
+16 -7
View File
@@ -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
}
}
}