-
Notifications
You must be signed in to change notification settings - Fork 6
/
values.go
47 lines (42 loc) · 1.07 KB
/
values.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
package url
import (
"fmt"
"net/url"
"strconv"
)
// GetString extracts the named string out of values.
func GetString(values url.Values, name string) (value string, err error) {
if v, ok := values[name]; !ok {
err = fmt.Errorf("%s was not found", name)
return
} else {
return v[0], nil
}
}
// GetInt extracts the named int out of values.
func GetInt(values url.Values, name string) (value int, err error) {
if v, ok := values[name]; !ok {
err = fmt.Errorf("%s was not found", name)
} else {
value, err = strconv.Atoi(v[0])
}
return
}
// GetFloat64 extracts the named float64 out of values.
func GetFloat64(values url.Values, name string) (value float64, err error) {
if v, ok := values[name]; !ok {
err = fmt.Errorf("%s was not found", name)
} else {
value, err = strconv.ParseFloat(v[0], 64)
}
return
}
// GetStrings returns the string array associated with the name
func GetStrings(values url.Values, name string) (value []string, err error) {
if v, ok := values[name]; !ok {
err = fmt.Errorf("%s was not found", name)
return
} else {
return v, nil
}
}