修复字段名解析对于omit的处理

This commit is contained in:
白茶清欢 2025-02-17 18:10:51 +08:00
parent 670d2b5cb3
commit 6449c7399f
2 changed files with 4 additions and 1 deletions

View File

@ -30,4 +30,5 @@ const (
TagErrMsg = "err" // 验证失败错误信息tag
TagContentType = "content_type"
TagOutputContentType = "output_content_type"
TagNameOmitempty = "omitempty"
)

View File

@ -34,7 +34,9 @@ func (psf parseStructField) GetParamName(structField reflect.StructField) string
}
for _, tag := range paramNameTagList {
tagVal := structField.Tag.Get(tag)
if tagVal != "" {
tagVal = strings.TrimSuffix(strings.TrimPrefix(tagVal, define.TagNameOmitempty+","), ","+define.TagNameOmitempty)
tagVal = strings.Trim(tagVal, ",")
if tagVal != "" && tagVal != define.TagNameOmitempty {
return tagVal
}
}