fix: test failure

This commit is contained in:
kevin
2023-03-06 23:04:19 +08:00
committed by Kevin Wan
parent fb7664a764
commit a972f400c6
4 changed files with 77 additions and 21 deletions

View File

@@ -13,7 +13,10 @@ import (
"github.com/zeromicro/go-zero/internal/encoding"
)
const jsonTagKey = "json"
const (
jsonTagKey = "json"
jsonTagSep = ','
)
var (
fillDefaultUnmarshaler = mapping.NewUnmarshaler(jsonTagKey, mapping.WithDefault())
@@ -257,7 +260,14 @@ func buildStructFieldsInfo(tp reflect.Type) (*fieldInfo, error) {
func getTagName(field reflect.StructField) string {
if tag, ok := field.Tag.Lookup(jsonTagKey); ok {
return tag
if pos := strings.IndexByte(tag, jsonTagSep); pos >= 0 {
tag = tag[:pos]
}
tag = strings.TrimSpace(tag)
if len(tag) > 0 {
return tag
}
}
return field.Name