util-go/reflect/type.go
2019-01-07 14:28:24 +00:00

73 lines
1.5 KiB
Go

package reflect
import (
"reflect"
)
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(""))
)
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()
}
func ConvertStringToType() {
}