Skip to content

Commit

Permalink
refactor: modify the init logic for env tag options to make it more r…
Browse files Browse the repository at this point in the history
…easonable (#347)
  • Loading branch information
astak16 authored Dec 6, 2024
1 parent cb81472 commit 52e7186
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 52e7186

Please sign in to comment.