first commit
This commit is contained in:
commit
9bee051e56
11
README.md
Normal file
11
README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
## goref
|
||||||
|
|
||||||
|
一个interface反射库
|
||||||
|
|
||||||
|
## 类型断言方法
|
||||||
|
|
||||||
|
- IsSlice 是否是slice
|
||||||
|
- IsArray 是否是array
|
||||||
|
- ...
|
||||||
|
|
||||||
|
## 其他方法
|
141
type.go
Normal file
141
type.go
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
package goref
|
||||||
|
|
||||||
|
import "reflect"
|
||||||
|
|
||||||
|
func IsInt(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsInt8(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Int8
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsInt16(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Int16
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsInt32(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsInt64(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsUint(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Uint
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsUint8(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsUint16(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsUint32(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsUint64(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsInteger(val any) bool {
|
||||||
|
typeKind := reflect.TypeOf(val).Kind()
|
||||||
|
return typeKind >= reflect.Int && typeKind <= reflect.Uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsFloat32(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Float32
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsFloat64(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsFloat(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Float32 || typeOf.Kind() == reflect.Float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsNumber(val any) bool {
|
||||||
|
return IsInteger(val) || IsFloat(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsBool(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsString(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.String
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsArray(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Array
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsSlice(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Slice
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsList(val any) bool {
|
||||||
|
return IsArray(val) || IsSlice(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsMap(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Map
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsStruct(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Struct
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsInterface(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Interface
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsFunc(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Func
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsPointer(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsUnsafePointer(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.UnsafePointer
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsUintptr(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsChannel(val any) bool {
|
||||||
|
typeOf := reflect.TypeOf(val)
|
||||||
|
return typeOf.Kind() == reflect.Chan
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user