-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapper_int.go
39 lines (32 loc) · 955 Bytes
/
mapper_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
package structure
import (
"reflect"
"strconv"
)
func init() {
registerMapper(intType, boolType, int2boolMapper)
registerMapper(intType, intType, int2intMapper)
registerMapper(intType, uintType, int2uintMapper)
registerMapper(intType, float64Type, int2floatMapper)
registerMapper(intType, stringType, int2stringMapper)
}
func int2boolMapper(from reflect.Value, to reflect.Value, _ *Option) error {
to.SetBool(from.Int() != 0)
return nil
}
func int2intMapper(from reflect.Value, to reflect.Value, _ *Option) error {
to.SetInt(from.Int())
return nil
}
func int2uintMapper(from reflect.Value, to reflect.Value, _ *Option) error {
to.SetUint(uint64(from.Int()))
return nil
}
func int2floatMapper(from reflect.Value, to reflect.Value, _ *Option) error {
to.SetFloat(float64(from.Int()))
return nil
}
func int2stringMapper(from reflect.Value, to reflect.Value, _ *Option) error {
to.SetString(strconv.Itoa(int(from.Int())))
return nil
}