-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
options.go
161 lines (129 loc) · 3.31 KB
/
options.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package client
// WithInterface updates/gets resource with interface directly from a device.
func WithInterface(resourceInterface string) ResourceInterfaceOption {
return ResourceInterfaceOption{
resourceInterface: resourceInterface,
}
}
// WithSkipTwin gets resource directly from a device without using interface for client client.
func WithSkipTwin() SkipTwinOption {
return SkipTwinOption{}
}
type ResourceInterfaceOption struct {
resourceInterface string
}
func (r ResourceInterfaceOption) applyOnGet(opts getOptions) getOptions {
if r.resourceInterface != "" {
opts.resourceInterface = r.resourceInterface
}
return opts
}
func (r ResourceInterfaceOption) applyOnUpdate(opts updateOptions) updateOptions {
if r.resourceInterface != "" {
opts.resourceInterface = r.resourceInterface
}
return opts
}
type SkipTwinOption struct{}
func (r SkipTwinOption) applyOnGet(opts getOptions) getOptions {
opts.skipTwin = true
return opts
}
// GetOption option definition.
type GetOption = interface {
applyOnGet(opts getOptions) getOptions
}
type getOptions struct {
resourceInterface string
skipTwin bool
codec Codec
}
type updateOptions struct {
resourceInterface string
codec Codec
}
type createOptions struct {
codec Codec
}
// UpdateOption option definition.
type UpdateOption = interface {
applyOnUpdate(opts updateOptions) updateOptions
}
// UpdateOption option definition.
type GetDevicesOption = interface {
applyOnGetDevices(opts getDevicesOptions) getDevicesOptions
}
// CreateOption option definition.
type CreateOption = interface {
applyOnCreate(opts createOptions) createOptions
}
func WithDeviceIDs(deviceIDs ...string) DeviceIDsOption {
return DeviceIDsOption{
deviceIDs: deviceIDs,
}
}
type DeviceIDsOption struct {
deviceIDs []string
}
type getDevicesOptions struct {
deviceIDs []string
resourceTypes []string
}
func (r DeviceIDsOption) applyOnGetDevices(opts getDevicesOptions) getDevicesOptions {
opts.deviceIDs = r.deviceIDs
return opts
}
func WithResourceTypes(resourceTypes ...string) ResourceTypesOption {
return ResourceTypesOption{
resourceTypes: resourceTypes,
}
}
type ResourceTypesOption struct {
resourceTypes []string
}
func (r ResourceTypesOption) applyOnGetDevices(opts getDevicesOptions) getDevicesOptions {
opts.resourceTypes = r.resourceTypes
return opts
}
func WithCodec(codec Codec) CodecOption {
return CodecOption{
codec: codec,
}
}
type CodecOption struct {
codec Codec
}
func (r CodecOption) applyOnGet(opts getOptions) getOptions {
opts.codec = r.codec
return opts
}
func (r CodecOption) applyOnUpdate(opts updateOptions) updateOptions {
opts.codec = r.codec
return opts
}
func (r CodecOption) applyOnObserve(opts observeOptions) observeOptions {
opts.codec = r.codec
return opts
}
func (r CodecOption) applyOnDelete(opts deleteOptions) deleteOptions {
opts.codec = r.codec
return opts
}
func (r CodecOption) applyOnCreate(opts createOptions) createOptions {
opts.codec = r.codec
return opts
}
type observeOptions struct {
codec Codec
}
// ObserveOption option definition.
type ObserveOption = interface {
applyOnObserve(opts observeOptions) observeOptions
}
type deleteOptions struct {
codec Codec
}
// DeleteOption option definition.
type DeleteOption = interface {
applyOnDelete(opts deleteOptions) deleteOptions
}