-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
77 lines (70 loc) · 1.45 KB
/
helper.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
package wsrpc
import (
"bytes"
"encoding/json"
"reflect"
)
var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
var jsonNullValue = json.RawMessage([]byte("null"))
// IsJSONArray checks the input whether it is a JSON array or not.
func IsJSONArray(in []byte) bool {
dec := json.NewDecoder(bytes.NewReader(in))
t, err := dec.Token()
if err != nil {
return false
}
if d, ok := t.(json.Delim); ok {
switch d.String() {
case "[":
return true
default:
return false
}
}
return false
}
// IsJSONObject checks the input whether it is a JSON object or not.
func IsJSONObject(in []byte) bool {
dec := json.NewDecoder(bytes.NewReader(in))
t, err := dec.Token()
if err != nil {
return false
}
if d, ok := t.(json.Delim); ok {
switch d.String() {
case "{":
return true
default:
return false
}
}
return false
}
// IsJSONNull checks the input whether it is a JSON null value or not.
func IsJSONNull(in []byte) bool {
dec := json.NewDecoder(bytes.NewReader(in))
t, err := dec.Token()
if err != nil {
return false
}
if t == nil {
return true
}
return false
}
func getAllInParamInfo(fType reflect.Type) []reflect.Type {
length := fType.NumIn()
r := make([]reflect.Type, length)
for i := 0; i < length; i++ {
r[i] = fType.In(i)
}
return r
}
func getAllOutParamInfo(fType reflect.Type) []reflect.Type {
length := fType.NumOut()
r := make([]reflect.Type, length)
for i := 0; i < length; i++ {
r[i] = fType.Out(i)
}
return r
}