diff options
author | jan <jan@ruken.pw> | 2016-10-12 14:19:30 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-10-12 14:19:30 (UTC) |
commit | edccb755f60fd135e09db5c60385961eccc72818 (patch) | |
tree | 5fe8203a6becce2a6b6e0784e2d3b8729b52e03a /util | |
parent | def8ba82c69891244eb0f8eebe0cb0b3bb23955b (diff) |
bisschen cleanup, RemoveGrilFromList wird jetzt auch gecheckt auf list owner
Diffstat (limited to 'util')
-rw-r--r-- | util/util.go | 25 |
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 @@ | |||
1 | package util | ||
2 | |||
3 | import ( | ||
4 | "errors" | ||
5 | "strconv" | ||
6 | |||
7 | "github.com/julienschmidt/httprouter" | ||
8 | ) | ||
9 | |||
10 | func 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 | |||
23 | func ParseIDFromParams(p httprouter.Params) (int, error) { | ||
24 | return ParseNumberFromParams("id", p, true) | ||
25 | } | ||