Bendodroid
b2f62c7bb0
- Functionally equivalent to old version at present - Temperature and Humidity sensors not handled yet - Moved HTTP handlers around
45 lines
1 KiB
Go
45 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"gitlab.hamburg.ccc.de/ccchh/spaceapid/config"
|
|
"gitlab.hamburg.ccc.de/ccchh/spaceapid/handlers"
|
|
"gitlab.hamburg.ccc.de/ccchh/spaceapid/types"
|
|
"gitlab.hamburg.ccc.de/ccchh/spaceapid/util"
|
|
)
|
|
|
|
func main() {
|
|
// Get spaceapid configuration
|
|
conf := config.ParseConfiguration()
|
|
|
|
// Merge old state if present
|
|
util.MergeOldState(&conf.Response)
|
|
|
|
// Register signal handler
|
|
sc := make(chan os.Signal, 1)
|
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM)
|
|
go func(resp *types.SpaceAPIResponseV14) {
|
|
<-sc
|
|
log.Println("Saving state and shutting down...")
|
|
util.SaveCurrentState(*resp)
|
|
os.Exit(0)
|
|
}(&conf.Response)
|
|
|
|
// Register HTTP handlers
|
|
http.HandleFunc("/",
|
|
handlers.Root(&conf.Response),
|
|
)
|
|
http.HandleFunc("/state/open",
|
|
handlers.StateOpen(conf.Credentials, conf.Dynamic.State.Open.AllowedCredentials, &conf.Response),
|
|
)
|
|
|
|
// Start webserver
|
|
log.Println("Starting HTTP server...")
|
|
log.Fatalln(http.ListenAndServe(":8080", nil))
|
|
}
|