mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
move dockerhost into global config
This commit is contained in:
parent
062c4298f2
commit
a708951c80
14
config.go
14
config.go
@ -1,13 +1,23 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
sortField string
|
dockerHost string
|
||||||
|
sortField string
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultConfig = NewDefaultConfig()
|
var DefaultConfig = NewDefaultConfig()
|
||||||
|
|
||||||
func NewDefaultConfig() Config {
|
func NewDefaultConfig() Config {
|
||||||
|
docker := os.Getenv("DOCKER_HOST")
|
||||||
|
if docker == "" {
|
||||||
|
docker = "unix:///var/run/docker.sock"
|
||||||
|
}
|
||||||
return Config{
|
return Config{
|
||||||
sortField: "id",
|
dockerHost: docker,
|
||||||
|
sortField: "id",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
@ -12,18 +11,16 @@ var filters = map[string][]string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewContainerMap() *ContainerMap {
|
func NewContainerMap() *ContainerMap {
|
||||||
|
config := DefaultConfig
|
||||||
|
|
||||||
// init docker client
|
// init docker client
|
||||||
host := os.Getenv("DOCKER_HOST")
|
client, err := docker.NewClient(config.dockerHost)
|
||||||
if host == "" {
|
|
||||||
host = "unix:///var/run/docker.sock"
|
|
||||||
}
|
|
||||||
client, err := docker.NewClient(host)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cm := &ContainerMap{
|
cm := &ContainerMap{
|
||||||
config: DefaultConfig,
|
config: config,
|
||||||
client: client,
|
client: client,
|
||||||
containers: make(map[string]*Container),
|
containers: make(map[string]*Container),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user