-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
100 lines (98 loc) · 2 KB
/
util.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package arg
import (
"strconv"
)
func getBool(src string, dst interface{}) bool {
destination, correctType := dst.(*bool)
if !correctType {
return false
}
parsedValue, err := strconv.ParseBool(src)
if err != nil {
return false
}
*destination = parsedValue
return true
}
func getInt64(src string, dst interface{}) bool {
destination, correctType := dst.(*int64)
if !correctType {
return false
}
parsedValue, err := strconv.ParseInt(src, 0, 64)
if err != nil {
return false
}
*destination = parsedValue
return true
}
func getUint64(src string, dst interface{}) bool {
destination, correctType := dst.(*uint64)
if !correctType {
return false
}
parsedValue, err := strconv.ParseUint(src, 0, 64)
if err != nil {
return false
}
*destination = parsedValue
return true
}
func getFloat64(src string, dst interface{}) bool {
destination, correctType := dst.(*float64)
if !correctType {
return false
}
parsedValue, err := strconv.ParseFloat(src, 64)
if err != nil {
return false
}
*destination = parsedValue
return true
}
func getFloat64Slice(src []string, dst interface{}) bool {
destination, correctType := dst.(*[]float64)
if !correctType {
return false
}
for _, item := range src {
var value float64
if getFloat64(item, &value) {
*destination = append(*destination, value)
}
}
return true
}
func getInt64Slice(src []string, dst interface{}) bool {
destination, correctType := dst.(*[]int64)
if !correctType {
return false
}
for _, item := range src {
var value int64
if getInt64(item, &value) {
*destination = append(*destination, value)
}
}
return true
}
func getUint64Slice(src []string, dst interface{}) bool {
destination, correctType := dst.(*[]uint64)
if !correctType {
return false
}
for _, item := range src {
var value uint64
if getUint64(item, &value) {
*destination = append(*destination, value)
}
}
return true
}
func getRunes(src string) []rune {
var runes []rune
for _, r := range src {
runes = append(runes, r)
}
return runes
}