From 52e7186e71f67e4259b6f1f8d6a889368f4e3378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=9A=E5=AD=90uccs?= <1500846601@qq.com> Date: Fri, 6 Dec 2024 10:37:26 +0800 Subject: [PATCH] refactor: modify the init logic for env tag options to make it more reasonable (#347) --- env.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/env.go b/env.go index 4fa5b2e..9be6522 100644 --- a/env.go +++ b/env.go @@ -377,13 +377,9 @@ func doParseField( return err } - if params.Init && isStructPtr(refField) && refField.IsNil() { + if params.Init && isInvalidPtr(refField) { refField.Set(reflect.New(refField.Type().Elem())) refField = refField.Elem() - - if _, ok := opts.FuncMap[refField.Type()]; ok { - return nil - } } if refField.Kind() == reflect.Struct { @@ -843,6 +839,6 @@ func ToMap(env []string) map[string]string { return toMap(env) } -func isStructPtr(v reflect.Value) bool { - return reflect.Ptr == v.Kind() && v.Type().Elem().Kind() == reflect.Struct +func isInvalidPtr(v reflect.Value) bool { + return reflect.Ptr == v.Kind() && v.Elem().Kind() == reflect.Invalid }