-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
func_type.go
44 lines (37 loc) · 977 Bytes
/
func_type.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 dasel
import "reflect"
var TypeFunc = BasicFunction{
name: "type",
runFn: func(c *Context, s *Step, args []string) (Values, error) {
if err := requireNoArgs("type", args); err != nil {
return nil, err
}
input := s.inputs()
res := make(Values, 0)
for _, val := range input {
resStr := "unknown"
if val.IsNil() {
resStr = "null"
} else if val.IsDencodingMap() {
resStr = "object"
} else {
switch val.Kind() {
case reflect.Slice, reflect.Array:
resStr = "array"
case reflect.Map, reflect.Struct:
resStr = "object"
case reflect.String:
resStr = "string"
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Float32, reflect.Float64:
resStr = "number"
case reflect.Bool:
resStr = "bool"
}
}
res = append(res, ValueOf(resStr))
}
return res, nil
},
}