diff --git a/core/conf/config.go b/core/conf/config.go index 7d2e76e6..c39c73bf 100644 --- a/core/conf/config.go +++ b/core/conf/config.go @@ -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) diff --git a/core/conf/config_test.go b/core/conf/config_test.go index a0d15140..9667f93f 100644 --- a/core/conf/config_test.go +++ b/core/conf/config_test.go @@ -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{}