Make ParamInt generic (any int type)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
func ParamString(r *http.Request, param string) string {
|
||||
@@ -56,19 +57,7 @@ func ParamTime(r *http.Request, param string, def time.Time) time.Time {
|
||||
return t
|
||||
}
|
||||
|
||||
func ParamInt(r *http.Request, param string, def int) int {
|
||||
v := ParamString(r, param)
|
||||
if v == "" {
|
||||
return def
|
||||
}
|
||||
value, err := strconv.ParseInt(v, 10, 32)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
return int(value)
|
||||
}
|
||||
|
||||
func ParamInt64(r *http.Request, param string, def int64) int64 {
|
||||
func ParamInt[T constraints.Integer](r *http.Request, param string, def T) T {
|
||||
v := ParamString(r, param)
|
||||
if v == "" {
|
||||
return def
|
||||
@@ -77,7 +66,7 @@ func ParamInt64(r *http.Request, param string, def int64) int64 {
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
return value
|
||||
return T(value)
|
||||
}
|
||||
|
||||
func ParamInts(r *http.Request, param string) []int {
|
||||
|
||||
Reference in New Issue
Block a user