-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis.go
44 lines (40 loc) · 817 Bytes
/
is.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
40
41
42
43
44
package tox
import (
"reflect"
"strconv"
)
func IsNumber(i any) bool {
switch v := i.(type) {
case int, int8, int16, int32, int64,
uint, uint8, uint16, uint32, uint64,
float32, float64:
return true
case string:
if _, err := strconv.Atoi(v); err != nil {
return false
} else {
return true
}
default:
return false
}
}
func IsString(i any) bool {
switch i.(type) {
case []byte:
return true
case string:
return true
default:
return false
}
}
func IsArray(i any) bool {
if reflect.TypeOf(i).Kind() == reflect.Array || reflect.TypeOf(i).Kind() == reflect.Slice {
return true
} else if reflect.TypeOf(i).Kind() == reflect.Ptr && (reflect.TypeOf(i).Elem().Kind() == reflect.Array || reflect.TypeOf(i).Elem().Kind() == reflect.Slice) {
return true
} else {
return false
}
}