-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
68 lines (53 loc) · 911 Bytes
/
utils.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
65
66
67
68
package main
import (
"strconv"
"strings"
)
// Check if string value not empty and return value
// otherwise return default value
func StrEmpty(v, def string) (s string) {
if s = strings.Trim(v, " "); s != "" {
return s
}
return def
}
// Convert integer value to the string
func Int2Str(v interface{}) (s string) {
switch v.(type) {
case string:
s = v.(string)
case int:
s = strconv.Itoa(v.(int))
}
return
}
// Convert string value to the integer
func Str2Int(v interface{}) (i int) {
switch v.(type) {
case string:
i, _ = strconv.Atoi(v.(string))
case int:
i = v.(int)
}
return
}
// Convert string value to the boolean
func Str2Bool(v interface{}) (t bool) {
var i = 0
switch v.(type) {
case string:
i, _ = strconv.Atoi(v.(string))
case int:
i = v.(int)
case bool:
if v.(bool) == true {
i = 1
} else {
i = 0
}
}
if i > 0 {
t = true
}
return
}