Skip to content

Commit

Permalink
fix allow zero problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Erfan Momeni authored and Erfan Momeni committed Dec 8, 2022
1 parent 5573bc2 commit b9184fe
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func GetOrElse(v interface{}, def interface{}) interface{} {
return val.Elem().Interface()
}

func get(value reflect.Value, path string) reflect.Value {
func get(value reflect.Value, path string, opts ...option) reflect.Value {
options := newOptions(opts...)

if value.Kind() == reflect.Slice || value.Kind() == reflect.Array {
var resultSlice reflect.Value

Expand All @@ -57,7 +59,7 @@ func get(value reflect.Value, path string) reflect.Value {

resultValue := get(item, path)

if resultValue.Kind() == reflect.Invalid || resultValue.IsZero() {
if resultValue.Kind() == reflect.Invalid || (resultValue.IsZero() && !options.allowZero) {
continue
}

Expand Down

0 comments on commit b9184fe

Please sign in to comment.