增加枚举值描述解析

This commit is contained in:
2025-02-18 23:02:46 +08:00
parent e1191b8c05
commit f6c3e0380d
4 changed files with 100 additions and 62 deletions

View File

@ -150,3 +150,31 @@ func (psf parseStructFieldTag) Summary(structField reflect.StructField) string {
}
return paramName
}
// EnumDescription .枚举值详细描述
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 22:40 2025/2/18
func (psf parseStructFieldTag) EnumDescription(structField reflect.StructField) map[string]string {
defaultTagList := []string{define.TagNameEnumDescription}
res := map[string]string{}
for _, tag := range defaultTagList {
if tagVal, exist := structField.Tag.Lookup(tag); exist && len(tagVal) > 0 {
tagVal = strings.ReplaceAll(tagVal, "###", "`")
enumList := strings.Split(tagVal, "||")
for _, enum := range enumList {
enumArr := strings.Split(enum, ":")
if len(enumArr) < 2 {
continue
}
res[enumArr[0]] = strings.Join(enumArr[1:], ":")
}
return res
}
}
if len(res) == 0 {
return nil
}
return res
}