-
Notifications
You must be signed in to change notification settings - Fork 53
/
util.go
63 lines (59 loc) · 1022 Bytes
/
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
package ztype
import (
"reflect"
)
// GetType Get variable type
func GetType(s interface{}) string {
var varType string
switch s.(type) {
case int:
varType = "int"
case int8:
varType = "int8"
case int16:
varType = "int16"
case int32:
varType = "int32"
case int64:
varType = "int64"
case uint:
varType = "uint"
case uint8:
varType = "uint8"
case uint16:
varType = "uint16"
case uint32:
varType = "uint32"
case uint64:
varType = "uint64"
case float32:
varType = "float32"
case float64:
varType = "float64"
case bool:
varType = "bool"
case string:
varType = "string"
case []byte:
varType = "[]byte"
default:
v := reflect.ValueOf(s)
varType = v.Type().String()
}
return varType
}
func ReflectPtr(r reflect.Value) reflect.Value {
if r.Kind() == reflect.Ptr {
r = r.Elem()
}
return r
}
func InArray(needle, hystack interface{}) bool {
nt := ToString(needle)
for _, item := range Slice(hystack) {
if nt == ToString(item) {
return true
}
}
return false
}