aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2016-10-12 14:19:30 (UTC)
committerjan <jan@ruken.pw>2016-10-12 14:19:30 (UTC)
commitedccb755f60fd135e09db5c60385961eccc72818 (patch)
tree5fe8203a6becce2a6b6e0784e2d3b8729b52e03a /util
parentdef8ba82c69891244eb0f8eebe0cb0b3bb23955b (diff)
bisschen cleanup, RemoveGrilFromList wird jetzt auch gecheckt auf list owner
Diffstat (limited to 'util')
-rw-r--r--util/util.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/util/util.go b/util/util.go
new file mode 100644
index 0000000..f3845c9
--- /dev/null
+++ b/util/util.go
@@ -0,0 +1,25 @@
1package util
2
3import (
4 "errors"
5 "strconv"
6
7 "github.com/julienschmidt/httprouter"
8)
9
10func ParseNumberFromParams(name string, p httprouter.Params, unsigned bool) (int, error) {
11 snum := p.ByName(name)
12 num, err := strconv.Atoi(snum)
13 if err != nil {
14 return 0, err
15 }
16
17 if unsigned && num < 0 {
18 return 0, errors.New("number is negative")
19 }
20 return num, err
21}
22
23func ParseIDFromParams(p httprouter.Params) (int, error) {
24 return ParseNumberFromParams("id", p, true)
25}