seperate routes, provide robust handler types, use mux

This commit is contained in:
sentriz
2019-07-14 19:32:36 +01:00
parent cbe709025e
commit 5444b328fd
77 changed files with 11880 additions and 1011 deletions

39
server/parsing/parsing.go Normal file
View File

@@ -0,0 +1,39 @@
package parsing
import (
"fmt"
"net/http"
"strconv"
)
func GetStrParam(r *http.Request, key string) string {
return r.URL.Query().Get(key)
}
func GetStrParamOr(r *http.Request, key, or string) string {
val := GetStrParam(r, key)
if val == "" {
return or
}
return val
}
func GetIntParam(r *http.Request, key string) (int, error) {
strVal := r.URL.Query().Get(key)
if strVal == "" {
return 0, fmt.Errorf("no param with key `%s`", key)
}
val, err := strconv.Atoi(strVal)
if err != nil {
return 0, fmt.Errorf("not an int `%s`", strVal)
}
return val, nil
}
func GetIntParamOr(r *http.Request, key string, or int) int {
val, err := GetIntParam(r, key)
if err != nil {
return or
}
return val
}