-
Notifications
You must be signed in to change notification settings - Fork 1
/
xp_int.go
58 lines (48 loc) · 1011 Bytes
/
xp_int.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
package xparam
import (
"fmt"
"strconv"
)
//------------------------------------------------------------
// Xparam access for int
//------------------------------------------------------------
// Gets parameter as int.
func (xp XP) As_Int(key string) (n int) {
if val, ok := xp[key]; ok && val != nil {
if n, ok = val.(int); ok {
return
}
if f, ok := val.(float64); ok {
n = int(f) // this may kill precision !
return
} else {
n, _ = strconv.Atoi(fmt.Sprint(val))
}
}
return
}
// Gets parameter as int64.
func (xp XP) As_Int64(key string) (n int64) {
if val, ok := xp[key]; ok && val != nil {
if n, ok = val.(int64); ok {
return
}
if f, ok := val.(float64); ok {
n = int64(f)
return
} else {
ni, _ := strconv.Atoi(fmt.Sprint(val))
n = int64(ni)
}
}
return
}
// Gets parameter as int array.
func (xp XP) As_ArrayInt(key string) (data []int) {
if val, ok := xp[key]; ok && val != nil {
if data, ok = val.([]int); ok {
return
}
}
return
}