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

Support float64 for fuzzyint #469

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Changes from all commits
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
6 changes: 4 additions & 2 deletions helpers/fuzzyvalues.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type (
// FuzzyBool resolves boolean sent as strings, integers, float64 or boolean, json unmarshal defaults to true
FuzzyBool bool

// FuzzyInt resolves integer sent as string or integer
// FuzzyInt resolves integer sent as string, integer or float64
FuzzyInt int
)

Expand Down Expand Up @@ -96,8 +96,10 @@ func (fi *FuzzyInt) UnmarshalJSON(arg []byte) error {
}
*fi = FuzzyInt(ival)
}
case float64:
*fi = FuzzyInt(val) // Truncate float since should be an integer
default:
return errors.Errorf("Failed to unmarshal value<%v> with type<%T> as integer", arg, val)
return errors.Errorf("Failed to unmarshal value<%v> with type<%T> as integer", val, val)
}
return nil
}