-
Notifications
You must be signed in to change notification settings - Fork 2
/
sds_helpers.go
64 lines (55 loc) · 1.23 KB
/
sds_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"log"
"net/http"
"strconv"
"strings"
)
func getURLQueryParamFloat(r *http.Request, keyname string) (float64, bool) {
keys, ok := r.URL.Query()[keyname]
if !ok || len(keys[0]) < 1 {
return 0.0, false
}
retval, err := strconv.ParseFloat(keys[0], 64)
if err != nil {
log.Println("Url Param ", keyname, " is invalid")
return 0.0, false
}
return retval, true
}
func getURLQueryParamInt(r *http.Request, keyname string) (int, bool) {
keys, ok := r.URL.Query()[keyname]
if !ok || len(keys[0]) < 1 {
return 0, false
}
retval, err := strconv.Atoi(keys[0])
if err != nil {
log.Println("Url Param ", keyname, " is invalid")
return 0, false
}
return retval, true
}
func getURLQueryParamString(r *http.Request, keyname string) (string, bool) {
keys, ok := r.URL.Query()[keyname]
if !ok || len(keys[0]) < 1 {
return "", false
}
return keys[0], true
}
func getURLArgumentInt(url string, positionNum int) (int, bool) {
pathData := strings.Split(url, "/")
param := pathData[positionNum]
retval, err := strconv.Atoi(param)
if err != nil {
return 0, false
}
return retval, true
}
func intInSlice(a int, list []int) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}