func main() { c := config.NewConfig("example.conf") err := c.Read() fmt.Println(err) fmt.Println(c) fmt.Println(c.Get("test", "a")) fmt.Println(c.Get("", "dd")) c.WriteTo("example2.conf") }
func load(confPath string) { if _, err := os.Stat(confPath); !os.IsNotExist(err) { conf := config.NewConfig(confPath) conf.Read() lampConfig = conf configureLog() } else { printVerboseMessage("Could not read config file: " + err.Error()) } }
func poll(client *http.Client, c chan string) { syslog.Info("Launch plex poller") conf := config.NewConfig(EtcDir + "/cinefade.conf") err := conf.Read() if err != nil { syslog.Critf("cannot read config: %v", err) } plexUrl := conf.Get("", "plexUrl") for { select { case <-r: syslog.Info("Exit from plex poller") r <- true return case <-time.After(5000 * time.Millisecond): req, _ := http.NewRequest("GET", plexUrl, nil) resp, err := client.Do(req) if err != nil { syslog.Warningf("can't access plex %v", err) c <- "unknown" } else { defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) var m MediaContainer xml.Unmarshal(body, &m) if err != nil { syslog.Critf("error: %v", err) } switch m.Video.Player.State { case "": c <- "stopped" case "paused": c <- "paused" case "playing": c <- "playing" default: c <- "unknown" } } } } }
// WriterLogger creates a new logger from a configuration file func ConfigLogger(filename string) (*Logger, error) { conf := config.NewConfig(filename) err := conf.Read() if err != nil { return nil, err } name := conf.Get("", "name") slevel := conf.Get("", "level") if slevel == "" { slevel = "0" } l, err := strconv.Atoi(slevel) if err != nil { return nil, err } level := Level(l) format := conf.Get("", "format") if format == "" { format = BasicFormat } timeFormat := conf.Get("", "timeFormat") if timeFormat == "" { timeFormat = DefaultTimeFormat } ssync := conf.Get("", "sync") if ssync == "" { ssync = "0" } file := conf.Get("", "file") if file == "" { file = DefaultFileName } sync := true if ssync == "0" { sync = false } else if ssync == "1" { sync = true } else { return nil, err } return FileLogger(name, level, format, timeFormat, file, sync) }
func GetBridge(debug bool) *hue.Bridge { conf := config.NewConfig(EtcDir + "/cinefade.conf") err := conf.Read() if err != nil { syslog.Critf("cannot read config: %v", err) os.Exit(1) } hueIpAddr := conf.Get("", "hueIpAddr") hueUser := conf.Get("", "hueUser") if hueIpAddr == "" || hueUser == "" { syslog.Crit("One of configuration hueIpAddr|hueUser not found") } bridge := hue.NewBridge(hueIpAddr, hueUser) if debug { bridge.Debug() } return bridge }