-
Notifications
You must be signed in to change notification settings - Fork 555
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
Implement positive number tag #388
Comments
Possibly using: func isPositiveNumber(v interface{}, _ interface{}) bool {
if v == nil { return false }
switch v.(type) {
case []uint:
for _, vv := range v.([]uint) {
if !isPositiveNumber(vv, nil) { return false }
}
return true
case []int:
for _, vv := range v.([]int) {
if !isPositiveNumber(vv, nil) { return false }
}
return true
case int:
break
case int16:
break
case int32:
break
case int64:
break
case uint:
break
case uint16:
break
case uint32:
break
case uint64:
break
case float32:
break
case float64:
break
default:
logrus.Warnf("field is not type numeric: '%s'", v)
return false
}
if i, ok := v.(uint); ok {
return i > 0
}
if i, ok := v.(int); ok {
return i > 0
}
if i, ok := v.(int64); ok {
return i > 0
}
if i, ok := v.(int32); ok {
return i > 0
}
if i, ok := v.(uint32); ok {
return i > 0
}
if i, ok := v.(uint64); ok {
return i > 0
}
if i, ok := v.(float64); ok {
return i > 0
}
if i, ok := v.(float32); ok {
return i > 0
}
logrus.Errorf("unsupported type for positive check: %+v (%s)", v, reflect.TypeOf(v).Kind().String())
return false
} |
Hello guys! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replacement struct tag for
IsPositive
.The text was updated successfully, but these errors were encountered: