-
Notifications
You must be signed in to change notification settings - Fork 546
/
types.go
40 lines (32 loc) · 1016 Bytes
/
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
package types
import (
"fmt"
"reflect"
)
// -----------------------------------------------------------------------------
var (
Var = reflect.TypeOf((*interface{})(nil)).Elem()
)
func Reflect(typ interface{}) reflect.Type {
if t, ok := typ.(string); ok {
if v, ok := builtinTypes[t]; ok {
return v
}
} else if t, ok := typ.(reflect.Type); ok {
return t
}
panic(fmt.Errorf("unknown type: `%v`", typ))
}
var builtinTypes = map[string]reflect.Type{
"int": reflect.TypeOf(0),
"bool": reflect.TypeOf(false),
"float": reflect.TypeOf(float64(0)),
"string": reflect.TypeOf(""),
"byte": reflect.TypeOf(byte(0)),
"var": Var,
"string:int": reflect.TypeOf(map[string]int(nil)),
"string:float": reflect.TypeOf(map[string]float64(nil)),
"string:string": reflect.TypeOf(map[string]string(nil)),
"string:var": reflect.TypeOf(map[string]interface{}(nil)),
}
// -----------------------------------------------------------------------------