ctop/config/main.go

51 lines
822 B
Go
Raw Normal View History

2017-02-07 03:33:09 +00:00
package config
2017-01-03 17:37:09 +00:00
2017-01-04 17:50:49 +00:00
import (
"os"
)
2017-02-07 03:33:09 +00:00
var Global = 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
}
2017-02-07 03:33:09 +00:00
func Update(k, v string) {
//log.Noticef("config update: %s = %s", k, v)
configChan <- ConfigMsg{k, v}
}
2017-01-03 17:37:09 +00:00
2017-01-12 19:48:29 +00:00
// Toggle a boolean option
2017-02-07 03:33:09 +00:00
func Toggle(k string) {
if Global[k] == "0" {
Global[k] = "1"
2017-01-12 19:48:29 +00:00
} else {
2017-02-07 03:33:09 +00:00
Global[k] = "0"
2017-01-12 19:48:29 +00:00
}
}
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{
"dockerHost": docker,
"filterStr": "",
"sortField": "id",
"sortReverse": "0",
"enableHeader": "0",
"loggingEnabled": "1",
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
}