-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.go
92 lines (67 loc) · 2.03 KB
/
validate.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package goonung
import (
"reflect"
)
var (
is bool
err error
)
func validate(param interface{}, kinds ...reflect.Kind) (bool, error) {
var val = reflect.ValueOf(param)
for _, kind := range kinds {
if kind == val.Kind() {
return true, nil
}
}
return false, nil
}
// IsArray : method to check the param is array
func IsArray(param interface{}) (bool, error) {
is, err = validate(param, reflect.Array)
return is, err
}
// IsBool : method to check the param is boolean
func IsBool(param interface{}) (bool, error) {
is, err = validate(param, reflect.Bool)
return is, err
}
// IsComplex : method to check the param is complex
func IsComplex(param interface{}) (bool, error) {
is, err = validate(param, reflect.Complex64, reflect.Complex128)
return is, err
}
// IsFloat : method to check the param is float
func IsFloat(param interface{}) (bool, error) {
is, err = validate(param, reflect.Float32, reflect.Float64)
return is, err
}
// IsInt : method to check the param is integer
func IsInt(param interface{}) (bool, error) {
is, err = validate(param, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64)
return is, err
}
// IsSlice : method to check the param is slice
func IsSlice(param interface{}) (bool, error) {
is, err = validate(param, reflect.Slice)
return is, err
}
// IsString : method to check the param is string
func IsString(param interface{}) (bool, error) {
is, err = validate(param, reflect.String)
return is, err
}
// IsStruct : method to check the param is struct
func IsStruct(param interface{}) (bool, error) {
is, err = validate(param, reflect.Struct)
return is, err
}
// IsUint : method to check the param is unsigned integer
func IsUint(param interface{}) (bool, error) {
is, err = validate(param, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64)
return is, err
}
// IsUintPtr : method to check the param is unsigned integer pointer (unsafe)
func IsUintPtr(param interface{}) (bool, error) {
is, err = validate(param, reflect.Uintptr)
return is, err
}