// vim: shiftwidth=4 tabstop=4 noexpandtab package main import ( "log" "time" "os" "io/ioutil" "encoding/json" ) const ( CONFIG_FILE = "/etc/birdscan/config.json" ) type config struct { WebConfig webConfig `json:"webserver"` } func main() { log.SetFlags(0) // disable timestamp because systemd takes care of that log.Println("Starting birdscan") cfg := readConfig() go runServer(&cfg.WebConfig) for { time.Sleep(1 * time.Second) } } func readConfig() config { log.Printf("Reading config file %s", CONFIG_FILE) var retval config // open the config file configFile, err := os.Open(CONFIG_FILE) defer configFile.Close() if err != nil { log.Fatalf("Could not open configuration file %s", CONFIG_FILE) } // read byte content byteData, err := ioutil.ReadAll(configFile) if err != nil { log.Fatalf("Could not read configuration file %s", CONFIG_FILE) } // parse content to config structs err = json.Unmarshal(byteData, &retval) if err != nil { log.Fatalf("Could not parse configuration file %s", CONFIG_FILE) } return retval }