ctop/config/main.go

46 lines
960 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 (
"fmt"
2017-01-04 17:50:49 +00:00
"os"
"sync"
"github.com/bcicen/ctop/logging"
2017-01-04 17:50:49 +00:00
)
2017-02-09 03:49:46 +00:00
var (
GlobalParams []*Param
GlobalSwitches []*Switch
GlobalWidgets []*Widget
lock sync.RWMutex
log = logging.Init()
2017-02-09 03:49:46 +00:00
)
func Init() {
for _, p := range defaultParams {
GlobalParams = append(GlobalParams, p)
log.Infof("loaded default config param: %s: %s", quote(p.Key), quote(p.Val))
2017-01-03 17:37:09 +00:00
}
for _, s := range defaultSwitches {
GlobalSwitches = append(GlobalSwitches, s)
log.Infof("loaded default config switch: %s: %t", quote(s.Key), s.Val)
}
for _, w := range defaultWidgets {
GlobalWidgets = append(GlobalWidgets, w)
log.Infof("loaded default widget: %s: %t", quote(w.Name), w.Enabled)
}
2017-01-03 17:37:09 +00:00
}
func quote(s string) string {
return fmt.Sprintf("\"%s\"", s)
}
// Return env var value if set, else return defaultVal
func getEnv(key, defaultVal string) string {
val := os.Getenv(key)
if val != "" {
return val
}
return defaultVal
}