util/reflect/type.go

73 lines
1.5 KiB
Go
Raw Normal View History

2018-03-20 02:38:36 +00:00
package reflect
import (
"reflect"
)
2018-03-20 05:12:31 +00:00
var (
TypeOf = reflect.TypeOf
)
var (
Types = []reflect.Type{
TypeBool,
TypeInt,
TypeInt8,
TypeInt16,
TypeInt32,
TypeInt64,
TypeUint,
TypeUint8,
TypeUint16,
TypeUint32,
TypeUint64,
TypeFloat32,
TypeFloat64,
TypeComplex64,
TypeComplex128,
TypeUintptr,
TypeString,
}
TypeInvalid = reflect.Type(nil)
TypeBool = reflect.TypeOf(false)
TypeInt = reflect.TypeOf(int(0))
TypeInt8 = reflect.TypeOf(int8(0))
TypeInt16 = reflect.TypeOf(int16(0))
TypeInt32 = reflect.TypeOf(int32(0))
TypeInt64 = reflect.TypeOf(int64(0))
TypeUint = reflect.TypeOf(uint(0))
TypeUint8 = reflect.TypeOf(uint8(0))
TypeUint16 = reflect.TypeOf(uint16(0))
TypeUint32 = reflect.TypeOf(uint32(0))
TypeUint64 = reflect.TypeOf(uint64(0))
TypeFloat32 = reflect.TypeOf(float32(0))
TypeFloat64 = reflect.TypeOf(float64(0))
TypeComplex64 = reflect.TypeOf(complex64(0))
TypeComplex128 = reflect.TypeOf(complex128(0))
TypeUintptr = reflect.TypeOf(uintptr(0))
TypeString = reflect.TypeOf(string(""))
)
2018-03-20 02:38:36 +00:00
func IsTypeKind(t reflect.Type, kind reflect.Kind, removePtr bool) bool {
if reflect.Ptr == t.Kind() {
if removePtr {
return IsTypeKind(t.Elem(), kind, removePtr)
}
}
return kind == t.Kind()
}
func GetTypeInfo(t reflect.Type) (realType reflect.Type, pkgName string, name string) {
if reflect.Ptr == t.Kind() {
return GetTypeInfo(t.Elem())
}
return t, t.PkgPath(), t.Name()
}
2018-03-20 05:12:31 +00:00
func ConvertStringToType() {
}