First working? version with persistent state
This commit is contained in:
parent
4eb1f18bf5
commit
8a1cf0456a
3 changed files with 102 additions and 1 deletions
18
main.go
18
main.go
|
@ -3,6 +3,9 @@ package main
|
|||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"gitlab.hamburg.ccc.de/ccchh/spaceapid/handlers"
|
||||
"gitlab.hamburg.ccc.de/ccchh/spaceapid/util"
|
||||
|
@ -15,10 +18,23 @@ func main() {
|
|||
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...")
|
||||
log.Fatalln(http.ListenAndServe(":8080", nil))
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue