-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameter_from_url.go
55 lines (50 loc) · 1017 Bytes
/
parameter_from_url.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
package gohttplib
import (
"net/http"
"strconv"
)
func IntParameterFromURLInRequest(r *http.Request, name string) *int {
s := GetParameterFromURLInRequest(r, name)
if s == nil {
return nil
}
i64, err := strconv.ParseInt(*s, 10, 64)
if err != nil {
return nil
}
i := int(i64)
return &i
}
func Int64ParameterFromURLInRequest(r *http.Request, name string) *int64 {
s := GetParameterFromURLInRequest(r, name)
if s == nil {
return nil
}
i64, err := strconv.ParseInt(*s, 10, 64)
if err != nil {
return nil
}
return &i64
}
func BoolParameterFromURLInRequest(r *http.Request, name string) *bool {
s := GetParameterFromURLInRequest(r, name)
if s == nil {
return nil
}
b, err := strconv.ParseBool(*s)
if err != nil {
return nil
}
return &b
}
func FloatParameterFromURLInRequest(r *http.Request, name string) *float64 {
s := GetParameterFromURLInRequest(r, name)
if s == nil {
return nil
}
float, err := strconv.ParseFloat(*s, 64)
if err != nil {
return nil
}
return &float
}