|
@@ -408,21 +408,49 @@ var (
|
|
|
|
|
|
validationParamFunctions = map[string]func(interface{}, interface{}) *errs.Error{
|
|
|
"min": func(value interface{}, minString interface{}) *errs.Error {
|
|
|
- min, err := strconv.Atoi(minString.(string))
|
|
|
- if err != nil || value.(int) < min {
|
|
|
+ var input float64
|
|
|
+
|
|
|
+ if v, ok := value.(int64); ok {
|
|
|
+ input = float64(v)
|
|
|
+ } else if v, ok := value.(float64); ok {
|
|
|
+ input = v
|
|
|
+ } else if v, ok := value.(string); ok {
|
|
|
+ input = float64(len(v))
|
|
|
+ } else {
|
|
|
invalidArgument := errs.InvalidArgument()
|
|
|
- invalidArgument.Message = fmt.Sprintf("ValueRestriction: value > %s. Received (%d)", minString, value)
|
|
|
+ invalidArgument.Message = fmt.Sprintf("ValueRestriction: mim validation requires (int,float,string)")
|
|
|
+ return invalidArgument
|
|
|
+ }
|
|
|
+
|
|
|
+ if min, convert := minString.(float64); !convert || input < min {
|
|
|
+ invalidArgument := errs.InvalidArgument()
|
|
|
+ invalidArgument.Message = fmt.Sprintf("ValueRestriction: value > %v. Received (%v)", minString, value)
|
|
|
return invalidArgument
|
|
|
}
|
|
|
return nil
|
|
|
},
|
|
|
"max": func(value interface{}, maxString interface{}) *errs.Error {
|
|
|
- max, err := strconv.Atoi(maxString.(string))
|
|
|
- if err != nil || value.(int) > max {
|
|
|
+
|
|
|
+ var input float64
|
|
|
+
|
|
|
+ if v, ok := value.(int64); ok {
|
|
|
+ input = float64(v)
|
|
|
+ } else if v, ok := value.(float64); ok {
|
|
|
+ input = v
|
|
|
+ } else if v, ok := value.(string); ok {
|
|
|
+ input = float64(len(v))
|
|
|
+ } else {
|
|
|
invalidArgument := errs.InvalidArgument()
|
|
|
- invalidArgument.Message = fmt.Sprintf("ValueRestriction: value < %s. Received (%d)", maxString, value)
|
|
|
+ invalidArgument.Message = fmt.Sprintf("ValueRestriction: mim validation requires (int,float,string)")
|
|
|
return invalidArgument
|
|
|
}
|
|
|
+
|
|
|
+ if max, convert := maxString.(float64); !convert || input > max {
|
|
|
+ invalidArgument := errs.InvalidArgument()
|
|
|
+ invalidArgument.Message = fmt.Sprintf("ValueRestriction: value < %v. Received (%v)", maxString, value)
|
|
|
+ return invalidArgument
|
|
|
+ }
|
|
|
+
|
|
|
return nil
|
|
|
},
|
|
|
"accept": func(input interface{}, accept interface{}) *errs.Error {
|