-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
96 lines (81 loc) · 2.4 KB
/
api.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
93
94
95
96
package pick
import (
"reflect"
"time"
)
type Notation interface {
Parse(selector string) ([]Key, error)
Format(path ...Key) string
}
type Traverser interface {
Retrieve(data any, path []Key) (any, error)
}
type ErrorGatherer interface {
GatherSelector(selector string, err error)
}
type Caster interface {
signedIntegerCaster
unsignedIntegerCaster
floatCaster
stringCaster
boolCaster
byteCaster
timeCaster
durationCaster
As(input any, asKind reflect.Kind) (any, error)
ByType(input any, asType reflect.Type) (any, error)
}
type signedIntegerCaster interface {
AsInt(item any) (int, error)
AsInt8(item any) (int8, error)
AsInt16(item any) (int16, error)
AsInt32(item any) (int32, error)
AsInt64(item any) (int64, error)
AsIntSlice(item any) ([]int, error)
AsInt8Slice(item any) ([]int8, error)
AsInt16Slice(item any) ([]int16, error)
AsInt32Slice(item any) ([]int32, error)
AsInt64Slice(item any) ([]int64, error)
}
type unsignedIntegerCaster interface {
AsUint(item any) (uint, error)
AsUint8(item any) (uint8, error)
AsUint16(item any) (uint16, error)
AsUint32(item any) (uint32, error)
AsUint64(item any) (uint64, error)
AsUintSlice(item any) ([]uint, error)
AsUint8Slice(item any) ([]uint8, error)
AsUint16Slice(item any) ([]uint16, error)
AsUint32Slice(item any) ([]uint32, error)
AsUint64Slice(item any) ([]uint64, error)
}
type floatCaster interface {
AsFloat32(item any) (float32, error)
AsFloat64(item any) (float64, error)
AsFloat32Slice(item any) ([]float32, error)
AsFloat64Slice(item any) ([]float64, error)
}
type stringCaster interface {
AsString(item any) (string, error)
AsStringSlice(item any) ([]string, error)
}
type boolCaster interface {
AsBool(item any) (bool, error)
AsBoolSlice(input any) ([]bool, error)
}
type byteCaster interface {
AsByte(item any) (byte, error)
AsByteSlice(input any) ([]byte, error)
}
type timeCaster interface {
AsTime(input any) (time.Time, error)
AsTimeWithConfig(config TimeCastConfig, input any) (time.Time, error)
AsTimeSlice(input any) ([]time.Time, error)
AsTimeSliceWithConfig(config TimeCastConfig, input any) ([]time.Time, error)
}
type durationCaster interface {
AsDuration(input any) (time.Duration, error)
AsDurationWithConfig(config DurationCastConfig, input any) (time.Duration, error)
AsDurationSlice(input any) ([]time.Duration, error)
AsDurationSliceWithConfig(config DurationCastConfig, input any) ([]time.Duration, error)
}