Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix allow zero option problem in get func #162

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix allow zero problem
  • Loading branch information
Erfan Momeni authored and Erfan Momeni committed Dec 8, 2022
commit b9184fef724d65eeea449a544e7c9095fc6d4fcb
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