-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathvalue_types.go
More file actions
53 lines (48 loc) · 1.08 KB
/
value_types.go
File metadata and controls
53 lines (48 loc) · 1.08 KB
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
package mapper
import (
"reflect"
"strconv"
"strings"
"time"
)
func strFunc(str string) reflect.Value {
return reflect.ValueOf(str)
}
//Support computing
func int64Func(str string) reflect.Value {
str = strings.TrimSpace(str)
if strings.Contains(str, "*") {
ss := strings.Split(str, "*")
var r int64
r = 1
for _, s := range ss {
r = r * int64Func(s).Int()
}
return reflect.ValueOf(r)
} else {
r, _ := strconv.ParseInt(str, 10, 64)
return reflect.ValueOf(r)
}
}
func uint64Func(str string) reflect.Value {
r, _ := strconv.ParseUint(str, 10, 64)
return reflect.ValueOf(r)
}
func boolFunc(str string) reflect.Value {
b, _ := strconv.ParseBool(str)
return reflect.ValueOf(b)
}
func float64Func(str string) reflect.Value {
r, _ := strconv.ParseFloat(str, 64)
return reflect.ValueOf(r)
}
func dateTimeFunc(str string) reflect.Value {
s := strings.Split(str, ";")
var t time.Time
if len(s) == 1 {
t, _ = time.ParseInLocation(defaultTimeLayout, str, time.Local)
} else if len(s) == 2 {
t, _ = time.ParseInLocation(s[1], s[0], time.Local)
}
return reflect.ValueOf(t)
}