/
options.go
152 lines (122 loc) · 3.18 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
package client
import (
kitNetCoap "github.com/plgd-dev/kit/net/coap"
)
// WithInterface updates/gets resource with interface directly from a device.
func WithInterface(resourceInterface string) ResourceInterfaceOption {
return ResourceInterfaceOption{
resourceInterface: resourceInterface,
}
}
// WithSkipShadow gets resource directly from a device without using interface for client client.
func WithSkipShadow() SkipShadowOption {
return SkipShadowOption{}
}
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 SkipShadowOption struct {
}
func (r SkipShadowOption) applyOnGet(opts getOptions) getOptions {
opts.skipShadow = true
return opts
}
// GetOption option definition.
type GetOption = interface {
applyOnGet(opts getOptions) getOptions
}
type getOptions struct {
resourceInterface string
skipShadow bool
codec kitNetCoap.Codec
}
type updateOptions struct {
resourceInterface string
codec kitNetCoap.Codec
}
// UpdateOption option definition.
type UpdateOption = interface {
applyOnUpdate(opts updateOptions) updateOptions
}
// UpdateOption option definition.
type GetDevicesOption = interface {
applyOnGetDevices(opts getDevicesOptions) getDevicesOptions
}
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 kitNetCoap.Codec) CodecOption {
return CodecOption{
codec: codec,
}
}
type CodecOption struct {
codec kitNetCoap.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
}
type observeOptions struct {
codec kitNetCoap.Codec
}
// ObserveOption option definition.
type ObserveOption = interface {
applyOnObserve(opts observeOptions) observeOptions
}
type deleteOptions struct {
codec kitNetCoap.Codec
}
// DeleteOption option definition.
type DeleteOption = interface {
applyOnDelete(opts deleteOptions) deleteOptions
}