ctop/config.go

48 lines
724 B
Go
Raw Normal View History

2017-01-03 17:37:09 +00:00
package main
2017-01-04 17:50:49 +00:00
import (
"os"
)
2017-01-06 13:49:22 +00:00
var GlobalConfig = NewDefaultConfig()
var configChan = make(chan ConfigMsg)
type Config map[string]string
type ConfigMsg struct {
key string
val string
2017-01-03 17:37:09 +00:00
}
func updateConfig(k, v string) {
configChan <- ConfigMsg{k, v}
}
2017-01-03 17:37:09 +00:00
2017-01-12 19:48:29 +00:00
// Toggle a boolean option
func (c Config) toggle(k string) {
if c[k] == "0" {
c[k] = "1"
} else {
c[k] = "0"
}
}
2017-01-03 17:37:09 +00:00
func NewDefaultConfig() Config {
2017-01-04 17:50:49 +00:00
docker := os.Getenv("DOCKER_HOST")
if docker == "" {
docker = "unix:///var/run/docker.sock"
}
config := Config{
2017-01-06 13:49:22 +00:00
"dockerHost": docker,
"sortField": "id",
2017-01-12 19:48:29 +00:00
"sortReverse": "0",
2017-01-06 13:49:22 +00:00
"enableHeader": "0",
2017-01-03 17:37:09 +00:00
}
go func() {
for m := range configChan {
config[m.key] = m.val
}
}()
return config
2017-01-03 17:37:09 +00:00
}