Skip to content

Commit bdd382a

Browse files
author
Pu Pu
committedMay 17, 2019
update
1 parent 8cf7650 commit bdd382a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed
 

‎handlers.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ func StringToInt(a interface{}) (interface{}, error) {
1818
if av, ok := a.(string); ok {
1919
if ai, err := strconv.Atoi(av); err == nil {
2020
return ai, nil
21+
} else {
22+
return 0, ErrConvertFailed
2123
}
2224
}
2325
return 0, ErrTypeNotMatch
@@ -27,21 +29,28 @@ func StringToStringSlice(a interface{}) (interface{}, error) {
2729
if av, ok := a.(string); ok {
2830
return strings.Split(av, ","), nil
2931
}
30-
return a, ErrTypeNotMatch
32+
return []string{}, ErrTypeNotMatch
3133
}
3234

3335
func StringToIntSlice(a interface{}) (interface{}, error) {
36+
bv := []int{}
3437
a, err := StringToStringSlice(a)
3538
if err != nil {
36-
return a, err
39+
return bv, err
3740
}
38-
bv := []int{}
3941
for _, row := range a.([]string) {
4042
rowInt, err := strconv.Atoi(row)
4143
if err != nil {
42-
return a, ErrConvertFailed
44+
return bv, ErrConvertFailed
4345
}
4446
bv = append(bv, rowInt)
4547
}
4648
return bv, nil
4749
}
50+
51+
func Int64ToInt(a interface{}) (interface{}, error) {
52+
if aInt64, ok := a.(int64); ok {
53+
return int(aInt64), nil
54+
}
55+
return 0, ErrTypeNotMatch
56+
}

0 commit comments

Comments
 (0)
Please sign in to comment.