diff options
Diffstat (limited to 'srv/api/utils.go')
-rw-r--r-- | srv/api/utils.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/srv/api/utils.go b/srv/api/utils.go index 8e2a63b..7662e17 100644 --- a/srv/api/utils.go +++ b/srv/api/utils.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "net/http" + "strconv" "github.com/mediocregopher/mediocre-go-lib/v2/mlog" ) @@ -58,3 +59,10 @@ func internalServerError(rw http.ResponseWriter, r *http.Request, err error) { Error: "internal server error", }) } + +func strToInt(str string, defaultVal int) (int, error) { + if str == "" { + return defaultVal, nil + } + return strconv.Atoi(str) +} |