re-use r.URL.Query
This commit is contained in:
@@ -19,13 +19,13 @@ type Number interface {
|
||||
// NumberParam from request query string
|
||||
func NumberParam[T Number](r *http.Request, key string) (T, error) {
|
||||
var noop T
|
||||
if !r.URL.Query().Has(key) {
|
||||
q := r.URL.Query()
|
||||
if !q.Has(key) {
|
||||
return noop, fmt.Errorf("query param: %q is missing", key)
|
||||
}
|
||||
|
||||
p := r.URL.Query().Get(key)
|
||||
t := reflect.TypeOf(noop)
|
||||
k := t.Kind()
|
||||
p := q.Get(key)
|
||||
k := reflect.TypeOf(noop).Kind()
|
||||
// float param
|
||||
if k == reflect.Float32 || k == reflect.Float64 {
|
||||
n, err := strconv.ParseFloat(p, 64)
|
||||
|
||||
Reference in New Issue
Block a user