-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
33 lines (28 loc) · 801 Bytes
/
config.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
package main
import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
var (
// Configuration Keys
configDebug = "debug"
configMode = "mode"
configTarget = "target"
configListen = "listen"
// Default Configuration Values
defaultDebug = false
defaultMode = "serial"
defaultTarget = "/dev/ttyUSB0"
defaultListen = "[::]:3094"
)
func init() {
// Register Flags
pflag.Bool(configDebug, defaultDebug, "Whether to enable debug logging")
pflag.String(configMode, defaultMode, "The mode to connect to the unit (serial/tcp)")
pflag.String(configTarget, defaultTarget, "The address or serial device of the unit")
pflag.String(configListen, defaultListen, "Address to bind the API on.")
pflag.Parse()
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
panic(err)
}
}