mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
fix: should not conflict on lower members (#3095)
This commit is contained in:
parent
92f2676afc
commit
07f03ebd0c
@ -242,6 +242,10 @@ func buildStructFieldsInfo(tp reflect.Type) (*fieldInfo, error) {
|
||||
|
||||
for i := 0; i < tp.NumField(); i++ {
|
||||
field := tp.Field(i)
|
||||
if !field.IsExported() {
|
||||
continue
|
||||
}
|
||||
|
||||
name := getTagName(field)
|
||||
lowerCaseName := toLowerCase(name)
|
||||
ft := mapping.Deref(field.Type)
|
||||
|
@ -1040,6 +1040,24 @@ func TestLoadNamedFieldOverwritten(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestLoadLowerMemberShouldNotConflict(t *testing.T) {
|
||||
type (
|
||||
Redis struct {
|
||||
db uint
|
||||
}
|
||||
|
||||
Config struct {
|
||||
db uint
|
||||
Redis
|
||||
}
|
||||
)
|
||||
|
||||
var c Config
|
||||
assert.NoError(t, LoadFromJsonBytes([]byte(`{}`), &c))
|
||||
assert.Zero(t, c.db)
|
||||
assert.Zero(t, c.Redis.db)
|
||||
}
|
||||
|
||||
func TestFillDefaultUnmarshal(t *testing.T) {
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
type St struct{}
|
||||
|
Loading…
Reference in New Issue
Block a user