From a708951c80d84063873798b860fcc3a48cfb84b7 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Wed, 4 Jan 2017 17:50:49 +0000 Subject: [PATCH] move dockerhost into global config --- config.go | 14 ++++++++++++-- containermap.go | 11 ++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/config.go b/config.go index 13e8c4a..f6cb5f1 100644 --- a/config.go +++ b/config.go @@ -1,13 +1,23 @@ package main +import ( + "os" +) + type Config struct { - sortField string + dockerHost string + sortField string } var DefaultConfig = NewDefaultConfig() func NewDefaultConfig() Config { + docker := os.Getenv("DOCKER_HOST") + if docker == "" { + docker = "unix:///var/run/docker.sock" + } return Config{ - sortField: "id", + dockerHost: docker, + sortField: "id", } } diff --git a/containermap.go b/containermap.go index d7227fc..7a7465b 100644 --- a/containermap.go +++ b/containermap.go @@ -1,7 +1,6 @@ package main import ( - "os" "strings" "github.com/fsouza/go-dockerclient" @@ -12,18 +11,16 @@ var filters = map[string][]string{ } func NewContainerMap() *ContainerMap { + config := DefaultConfig + // init docker client - host := os.Getenv("DOCKER_HOST") - if host == "" { - host = "unix:///var/run/docker.sock" - } - client, err := docker.NewClient(host) + client, err := docker.NewClient(config.dockerHost) if err != nil { panic(err) } cm := &ContainerMap{ - config: DefaultConfig, + config: config, client: client, containers: make(map[string]*Container), }