Skip to content

Commit

Permalink
refactor: simplify the judgment logic of the isSliceOfStructs function
Browse files Browse the repository at this point in the history
  • Loading branch information
astak16 committed Dec 9, 2024
1 parent 2aa98f7 commit bda42a2
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,34 +408,21 @@ func doParseField(

func isSliceOfStructs(refTypeField reflect.StructField, opts Options) bool {

Check failure on line 409 in env.go

View workflow job for this annotation

GitHub Actions / lint

`isSliceOfStructs` - `opts` is unused (unparam)
field := refTypeField.Type
if field.Kind() == reflect.Ptr {
field = field.Elem()
}

if field.Kind() != reflect.Slice {
return false
}

field = field.Elem()

// *[]struct
if field.Kind() == reflect.Ptr {
field = field.Elem()
if field.Kind() == reflect.Slice && field.Elem().Kind() == reflect.Struct {
return true
}
}

_, ignore := defaultBuiltInParsers[field.Kind()]

if !ignore {
_, ignore = opts.FuncMap[field]
}

if !ignore {
_, ignore = reflect.New(field).Interface().(encoding.TextUnmarshaler)
// []struct{}
if field.Kind() == reflect.Slice && field.Elem().Kind() == reflect.Struct {
return true
}

if !ignore {
ignore = field.Kind() != reflect.Struct
}
return !ignore
return false
}

func doParseSlice(ref reflect.Value, processField processFieldFn, opts Options) error {
Expand Down

0 comments on commit bda42a2

Please sign in to comment.