// vim: shiftwidth=4 tabstop=4 noexpandtab package main import ( "flag" "log" "os" "io/ioutil" "encoding/json" ) var ( camera Camera ) type config struct { WebConfig webConfig `json:"webserver"` } func main() { // read command line arguments configPath := readFlags() // set up log and print startup message log.SetFlags(0) // disable timestamp because systemd takes care of that log.Println("Starting birdscan") // read config file cfg := readConfig(configPath) // setup camera state machine camera = NewCamera() // start goroutines server := NewWebServer(&cfg.WebConfig) go server.run() // http server // run camera state machine camera.run() } func readFlags() string { var retval string flag.StringVar(&retval, "c", "/etc/birdscan/config.json", "Path to birdscan configuration file") flag.Parse() return retval } func readConfig(path string) config { log.Printf("Reading config file %s", path) var retval config // open the config file configFile, err := os.Open(path) defer configFile.Close() if err != nil { log.Fatalf("Could not open configuration file %s", path) } // read byte content byteData, err := ioutil.ReadAll(configFile) if err != nil { log.Fatalf("Could not read configuration file %s", path) } // parse content to config structs err = json.Unmarshal(byteData, &retval) if err != nil { log.Fatalf("Could not parse configuration file %s", path) } return retval }