From 7294fd01819333c228e3725f29e4a11988af7bd2 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Wed, 5 Sep 2018 08:27:07 -0400 Subject: [PATCH] add float support --- api/server.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/server.go b/api/server.go index f18e3b9..7080292 100644 --- a/api/server.go +++ b/api/server.go @@ -236,6 +236,21 @@ func FormValues(r *http.Request, params interface{}, validationRules []*v.FieldR underscoredName, strings.Join(validator.GetBoolStringValues(), ", ")) } finalValue = reflect.ValueOf(validator.IsTruthy(value)) + + case reflect.Float32, reflect.Float64: + if value == "" { + continue + } + castVal, err := cast.ToFloat64E(value) + if err != nil { + return errors.Err("%s: must be a floating point number", underscoredName) + } + switch structFieldKind { + case reflect.Float32: + finalValue = reflect.ValueOf(float32(castVal)) + case reflect.Float64: + finalValue = reflect.ValueOf(float64(castVal)) + } default: return errors.Err("field %s is an unsupported type", name) }