142 lines
2.9 KiB
Go
142 lines
2.9 KiB
Go
|
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
|
||
|
}
|