-
Notifications
You must be signed in to change notification settings - Fork 0
/
cast_types.go
104 lines (98 loc) · 3.79 KB
/
cast_types.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
101
102
103
104
package pick
import (
"reflect"
"time"
)
// lets use this as global for performance reasons.
//
//nolint:gochecknoglobals
var castFunctionTypes = newDirectCastFunctionsTypes()
type directCastFunctionsTypes struct {
typeOfBool reflect.Type
// typeOfByte reflect.Type // there is no distinguish type for byte. Its only uint8.
typeOfInt8 reflect.Type
typeOfInt16 reflect.Type
typeOfInt32 reflect.Type
typeOfInt64 reflect.Type
typeOfInt reflect.Type
typeOfUint8 reflect.Type
typeOfUint16 reflect.Type
typeOfUint32 reflect.Type
typeOfUint64 reflect.Type
typeOfUint reflect.Type
typeOfFloat32 reflect.Type
typeOfFloat64 reflect.Type
typeOfString reflect.Type
typeOfTime reflect.Type
typeOfDuration reflect.Type
typeOfSliceBool reflect.Type
// typeOfSliceByte reflect.Type // there is no distinguish type for byte. Its only uint8.
typeOfSliceInt8 reflect.Type
typeOfSliceInt16 reflect.Type
typeOfSliceInt32 reflect.Type
typeOfSliceInt64 reflect.Type
typeOfSliceInt reflect.Type
typeOfSliceUint8 reflect.Type
typeOfSliceUint16 reflect.Type
typeOfSliceUint32 reflect.Type
typeOfSliceUint64 reflect.Type
typeOfSliceUint reflect.Type
typeOfSliceFloat32 reflect.Type
typeOfSliceFloat64 reflect.Type
typeOfSliceString reflect.Type
typeOfSliceTime reflect.Type
typeOfSliceDuration reflect.Type
basicKindTypeMap map[reflect.Kind]reflect.Type
}
func newDirectCastFunctionsTypes() directCastFunctionsTypes {
return directCastFunctionsTypes{
typeOfBool: reflect.TypeOf(false),
typeOfInt8: reflect.TypeOf(int8(0)),
typeOfInt16: reflect.TypeOf(int16(0)),
typeOfInt32: reflect.TypeOf(int32(0)),
typeOfInt64: reflect.TypeOf(int64(0)),
typeOfInt: reflect.TypeOf(int(0)),
typeOfUint8: reflect.TypeOf(uint8(0)),
typeOfUint16: reflect.TypeOf(uint16(0)),
typeOfUint32: reflect.TypeOf(uint32(0)),
typeOfUint64: reflect.TypeOf(uint64(0)),
typeOfUint: reflect.TypeOf(uint(0)),
typeOfFloat32: reflect.TypeOf(float32(0)),
typeOfFloat64: reflect.TypeOf(float64(0)),
typeOfString: reflect.TypeOf(""),
typeOfTime: reflect.TypeOf(time.Time{}),
typeOfDuration: reflect.TypeOf(time.Duration(0)),
typeOfSliceBool: reflect.TypeOf([]bool{}),
typeOfSliceInt8: reflect.TypeOf([]int8{}),
typeOfSliceInt16: reflect.TypeOf([]int16{}),
typeOfSliceInt32: reflect.TypeOf([]int32{}),
typeOfSliceInt64: reflect.TypeOf([]int64{}),
typeOfSliceInt: reflect.TypeOf([]int{}),
typeOfSliceUint8: reflect.TypeOf([]uint8{}),
typeOfSliceUint16: reflect.TypeOf([]uint16{}),
typeOfSliceUint32: reflect.TypeOf([]uint32{}),
typeOfSliceUint64: reflect.TypeOf([]uint64{}),
typeOfSliceUint: reflect.TypeOf([]uint{}),
typeOfSliceFloat32: reflect.TypeOf([]float32{}),
typeOfSliceFloat64: reflect.TypeOf([]float64{}),
typeOfSliceString: reflect.TypeOf([]string{}),
typeOfSliceTime: reflect.TypeOf([]time.Time{}),
typeOfSliceDuration: reflect.TypeOf([]time.Duration{}),
basicKindTypeMap: map[reflect.Kind]reflect.Type{
reflect.Bool: reflect.TypeOf(false),
reflect.Int: reflect.TypeOf(int(0)),
reflect.Int8: reflect.TypeOf(int8(0)),
reflect.Int16: reflect.TypeOf(int16(0)),
reflect.Int32: reflect.TypeOf(int32(0)),
reflect.Int64: reflect.TypeOf(int64(0)),
reflect.Uint: reflect.TypeOf(uint(0)),
reflect.Uint8: reflect.TypeOf(uint8(0)),
reflect.Uint16: reflect.TypeOf(uint16(0)),
reflect.Uint32: reflect.TypeOf(uint32(0)),
reflect.Uint64: reflect.TypeOf(uint64(0)),
reflect.Float32: reflect.TypeOf(float32(0)),
reflect.Float64: reflect.TypeOf(float64(0)),
reflect.String: reflect.TypeOf(""),
},
}
}