-
Notifications
You must be signed in to change notification settings - Fork 8
/
type.go
76 lines (65 loc) · 1.15 KB
/
type.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
package dproxy
// Type is type of value.
type Type int
const (
// Tunknown shows value is not supported.
Tunknown Type = iota
// Tnil shows value is nil.
Tnil
// Tbool shows value is bool.
Tbool
// Tint64 shows value is int64.
Tint64
// Tfloat64 shows value is float64.
Tfloat64
// Tstring shows value is string.
Tstring
// Tarray shows value is an array ([]interface{})
Tarray
// Tmap shows value is a map (map[string]interface{})
Tmap
)
// detectType returns type of a value.
func detectType(v interface{}) Type {
if v == nil {
return Tnil
}
switch v.(type) {
case bool:
return Tbool
case int, int32, int64:
return Tint64
case float32, float64:
return Tfloat64
case string:
return Tstring
case []interface{}:
return Tarray
case map[string]interface{}:
return Tmap
default:
return Tunknown
}
}
func (t Type) String() string {
switch t {
case Tunknown:
return "unknown"
case Tnil:
return "nil"
case Tbool:
return "bool"
case Tint64:
return "int64"
case Tfloat64:
return "float64"
case Tstring:
return "string"
case Tarray:
return "array"
case Tmap:
return "map"
default:
return "unknown"
}
}