-
Notifications
You must be signed in to change notification settings - Fork 110
/
robot_options.go
75 lines (62 loc) · 1.98 KB
/
robot_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
package robotimpl
import (
"go.viam.com/rdk/robot/web"
)
// options configures a Robot.
type options struct {
// webOptions are used to initially configure the web service.
webOptions []web.Option
// viamHomeDir is used to configure the Viam home directory.
viamHomeDir string
// revealSensitiveConfigDiffs will display config diffs - which may contain secret
// information - in log statements
revealSensitiveConfigDiffs bool
// shutdownCallback provides a callback for the robot to be able to shut itself down.
shutdownCallback func()
}
// Option configures how we set up the web service.
// Cribbed from https://github.com/grpc/grpc-go/blob/aff571cc86e6e7e740130dbbb32a9741558db805/dialoptions.go#L41
type Option interface {
apply(*options)
}
// funcOption wraps a function that modifies options into an
// implementation of the Option interface.
type funcOption struct {
f func(*options)
}
func (fdo *funcOption) apply(do *options) {
fdo.f(do)
}
func newFuncOption(f func(*options)) *funcOption {
return &funcOption{
f: f,
}
}
// WithWebOptions returns a Option which sets the streamConfig
// used to enable audio/video streaming over WebRTC.
func WithWebOptions(opts ...web.Option) Option {
return newFuncOption(func(o *options) {
o.webOptions = opts
})
}
// WithRevealSensitiveConfigDiffs returns an Option which causes config
// diffs - which may contain sensitive information - to be displayed
// in logs.
func WithRevealSensitiveConfigDiffs() Option {
return newFuncOption(func(o *options) {
o.revealSensitiveConfigDiffs = true
})
}
// WithViamHomeDir returns a Option which sets the Viam home directory.
func WithViamHomeDir(homeDir string) Option {
return newFuncOption(func(o *options) {
o.viamHomeDir = homeDir
})
}
// WithShutdownCallback returns a Option which provides a callback for the
// robot to be able to shut itself down.
func WithShutdownCallback(shutdownFunc func()) Option {
return newFuncOption(func(o *options) {
o.shutdownCallback = shutdownFunc
})
}