Extract common getenv-testing code
This commit is contained in:
1 parent
e2ec2b436d
commit
9ac62e8005
1 file changed
+13
-23
+13
-23
@@ -12,17 +12,21 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
version = "(unreleased version)"
|
||||
defaultDockerHost = "unix:///var/run/docker.sock"
|
||||
defaultProcPath = "/proc"
|
||||
defaultDockerBridge = "docker0"
|
||||
version = "(unreleased version)"
|
||||
)
|
||||
|
||||
func getenv(key, defaultVal string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return defaultVal
|
||||
}
|
||||
|
||||
func main() {
|
||||
var (
|
||||
justVersion bool
|
||||
logLevel = "info"
|
||||
c = proxy.Config{Image: "weaveworks/weaveexec"}
|
||||
c proxy.Config
|
||||
withDNS bool
|
||||
)
|
||||
|
||||
@@ -54,10 +58,6 @@ func main() {
|
||||
|
||||
SetLogLevel(logLevel)
|
||||
|
||||
if image := os.Getenv("EXEC_IMAGE"); image != "" {
|
||||
c.Image = image
|
||||
}
|
||||
|
||||
Log.Infoln("weave proxy", version)
|
||||
Log.Infoln("Command line arguments:", strings.Join(os.Args[1:], " "))
|
||||
|
||||
@@ -65,20 +65,10 @@ func main() {
|
||||
Log.Warning("--with-dns option has been removed; DNS is on by default")
|
||||
}
|
||||
|
||||
c.DockerBridge = defaultDockerBridge
|
||||
if dockerBridge := os.Getenv("DOCKER_BRIDGE"); dockerBridge != "" {
|
||||
c.DockerBridge = dockerBridge
|
||||
}
|
||||
|
||||
c.DockerHost = defaultDockerHost
|
||||
if dockerHost := os.Getenv("DOCKER_HOST"); dockerHost != "" {
|
||||
c.DockerHost = dockerHost
|
||||
}
|
||||
|
||||
c.ProcPath = defaultProcPath
|
||||
if procPath := os.Getenv("PROCFS"); procPath != "" {
|
||||
c.ProcPath = procPath
|
||||
}
|
||||
c.Image = getenv("EXEC_IMAGE", "weaveworks/weaveexec")
|
||||
c.DockerBridge = getenv("DOCKER_BRIDGE", "docker0")
|
||||
c.DockerHost = getenv("DOCKER_HOST", "unix:///var/run/docker.sock")
|
||||
c.ProcPath = getenv("PROCFS", "/proc")
|
||||
|
||||
p, err := proxy.NewProxy(c)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user