diff options
Diffstat (limited to 'src/main.go')
-rw-r--r-- | src/main.go | 72 |
1 files changed, 16 insertions, 56 deletions
diff --git a/src/main.go b/src/main.go index 01581ff..572e5f9 100644 --- a/src/main.go +++ b/src/main.go @@ -3,77 +3,37 @@ package main import ( - "flag" "log" - "os" - "io/ioutil" - "encoding/json" ) var ( + config RuntimeConfig camera Camera - debug bool + transporter Transporter ) -type config struct { - WebConfig webConfig `json:"webserver"` -} - func main() { - // read command line arguments - configPath := readFlags() + // disable log timestamp because systemd takes care of that + log.SetFlags(0) - // set up log and print startup message - log.SetFlags(0) // disable timestamp because systemd takes care of that - log.Println("Starting birdscan") + // parse flags and read config + config = GetRuntimeConfig() - // read config file - cfg := readConfig(configPath) + // print startup message + log.Println("Starting birdscan") - // setup camera state machine + // create camera camera = NewCamera() + // setup transporter + transporter = NewTransporter() + go transporter.Run() // daemon to copy files via rsync + // start goroutines - server := NewWebServer(&cfg.WebConfig) - go server.run() // http server + server := NewWebServer() + go server.run() // http server / user interface - // run camera state machine + // run camera camera.run() } - -func readFlags() string { - var retval string - flag.StringVar(&retval, "c", "/etc/birdscan/config.json", "Path to birdscan configuration file") - flag.BoolVar(&debug, "d", false, "A debug flag to be used by source repository Makefile") - 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 -} - |