package main import ( "log" "net/http" "os" "os/signal" "syscall" "gitlab.hamburg.ccc.de/ccchh/spaceapid/handlers" "gitlab.hamburg.ccc.de/ccchh/spaceapid/util" ) func main() { log.Println("Reading configuration values") config := util.GetConfiguration() log.Println("Reading initial SpaceAPI response from", config.TemplatePath) spaceApiResponse := util.ParseTemplate(config.TemplatePath) // Merge old state if present util.MergeOldState(&spaceApiResponse) // Register HTTP handlers http.HandleFunc("/", handlers.Root(&spaceApiResponse)) http.HandleFunc("/state/open", handlers.StateOpen(config.BAUsername, config.BAPassword, &spaceApiResponse)) // Start webserver log.Println("Starting HTTP server...") go log.Fatalln(http.ListenAndServe(":8080", nil)) // Wait for exit signal sc := make(chan os.Signal, 1) signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM) <-sc // Save state for next run log.Println("Saving state and shutting down...") util.SaveCurrentState(spaceApiResponse) }