-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
37 lines (33 loc) · 1.01 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
package rflink
import (
"github.com/vrischmann/envconfig"
)
// Options stores the options needed to communicate with RFLink and the
// message queue
type Options struct {
// MQTT options
Publish struct {
Host string `envconfig:"default=localhost:1883"` // host:port
Scheme string `envconfig:"default=tcp"`
MqttUsername string `envconfig:"default=username"`
MqttPassword string `envconfig:"default=password"`
ProtocolVersion uint `envconfig:"default=4"`
InfinityReconnect bool `envconfig:"default=true"`
ClientID string `envconfig:"default=gorflink"`
Topic string `envconfig:"default=rflink"`
}
// Serial connection options
Serial struct {
Device string `envconfig:"default=/dev/ttyUSB0"`
Baud int `envconfig:"default=57600"`
}
}
// GetOptions reads the options from the environment and returns an Options
// struct
func GetOptions() *Options {
var opts Options
if err := envconfig.Init(&opts); err != nil {
panic(err)
}
return &opts
}