This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
70 lines (63 loc) · 1.93 KB
/
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
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
// Package config provides for all configurable parameters dev-bridge can have
package config
import (
"time"
"github.com/levenlabs/go-llog"
"github.com/mediocregopher/lever"
)
// All possible configurable variables
var (
ListenAddr string
PingAddr string
SkyAPIAddr string
WhitelistedSuffixes []string
PingTimeout time.Duration
LogLevel string
)
func init() {
l := lever.New("dev-bridge", nil)
l.Add(lever.Param{
Name: "--listen-addr",
Description: "address to listen for http connections on",
Default: ":8888",
})
l.Add(lever.Param{
Name: "--ping-addr",
Description: "udp address that will listen for pings from hosts",
Default: ":4445",
})
l.Add(lever.Param{
Name: "--skyapi-addr",
Description: "Hostname of skyapi, to be looked up via a SRV request. Unset means don't register with skyapi",
})
l.Add(lever.Param{
Name: "--whitelist-suffix",
Description: "Only proxy requests whose Host has this suffix. Can be specified multiple times. If not specified, all Hosts allowed",
})
l.Add(lever.Param{
Name: "--ping-timeout",
Description: "Time before a machine must ping again (e.g. 5s, 3m5s)",
Default: "30s",
})
l.Add(lever.Param{
Name: "--log-level",
Description: "Minimum log level to show, either debug, info, warn, error, or fatal",
Default: "info",
})
l.Parse()
ListenAddr, _ = l.ParamStr("--listen-addr")
PingAddr, _ = l.ParamStr("--ping-addr")
SkyAPIAddr, _ = l.ParamStr("--skyapi-addr")
WhitelistedSuffixes, _ = l.ParamStrs("--whitelist-suffix")
LogLevel, _ = l.ParamStr("--log-level")
llog.SetLevelFromString(LogLevel)
pingTimeout, _ := l.ParamStr("--ping-timeout")
pingTimeoutParsed, err := time.ParseDuration(pingTimeout)
if err != nil {
llog.Fatal("invalid ping timeout passed in", llog.KV{
"pingTimeout": pingTimeout,
"err": err,
})
}
PingTimeout = pingTimeoutParsed
}