Skip to content

Commit b7f7c0f

Browse files
committed
fix: private filed no need to set
1 parent b7c7c7f commit b7f7c0f

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

env_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func Test_ReadEnv(t *testing.T) {
171171
type Manager struct {
172172
ClassName string `env:""`
173173
Filesystem *FileSystem
174+
filesystem *FileSystem
174175
FFSys FileSystem
175176
}
176177

marshal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func marshal(rv reflect.Value, m map[string]interface{}, prefix string) error {
4242

4343
// 2. 判断 fv 是否为 nil, 如果是尝试初始化
4444
fv := rv.Field(i)
45-
if fv.Kind() == reflect.Ptr && fv.IsNil() {
45+
if fv.Kind() == reflect.Ptr && fv.IsNil() && fv.CanSet() {
4646
// 注意: 反射对象要使用 Set() 方法,不能直接赋值。
4747
// fv = new(ft.Type)
4848
fv.Set(newValue(ft.Type))

0 commit comments

Comments
 (0)