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

FeatureRequest: ToBool add int* support #134

Closed
hxzhao527 opened this issue Jan 21, 2022 · 1 comment · Fixed by #153
Closed

FeatureRequest: ToBool add int* support #134

hxzhao527 opened this issue Jan 21, 2022 · 1 comment · Fixed by #153

Comments

@hxzhao527
Copy link

cast/caste.go

Lines 81 to 99 in 8807572

func ToBoolE(i interface{}) (bool, error) {
i = indirect(i)
switch b := i.(type) {
case bool:
return b, nil
case nil:
return false, nil
case int:
if i.(int) != 0 {
return true, nil
}
return false, nil
case string:
return strconv.ParseBool(i.(string))
default:
return false, fmt.Errorf("unable to cast %#v of type %T to bool", i, i)
}
}

there only assert type int, no int8, int16, int32, int64, uint ...

could we add these type case?

@hungnl-dev
Copy link

I got the same problem today as I used redismock which only return value in type int64, and couldn't convert to bool. So I have made a PR for that, I will link the PR to this issue for further discuss and review on this matter:
#135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants