First implementation of new config format
- Functionally equivalent to old version at present - Temperature and Humidity sensors not handled yet - Moved HTTP handlers around
This commit is contained in:
parent
7bb676887f
commit
b2f62c7bb0
7 changed files with 125 additions and 121 deletions
20
main.go
20
main.go
|
@ -7,20 +7,18 @@ import (
|
|||
"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() {
|
||||
log.Println("Reading configuration values")
|
||||
config := util.GetConfiguration()
|
||||
|
||||
log.Println("Reading initial SpaceAPI response from", config.TemplatePath)
|
||||
spaceApiResponse := util.ParseTemplate(config.TemplatePath)
|
||||
// Get spaceapid configuration
|
||||
conf := config.ParseConfiguration()
|
||||
|
||||
// Merge old state if present
|
||||
util.MergeOldState(&spaceApiResponse)
|
||||
util.MergeOldState(&conf.Response)
|
||||
|
||||
// Register signal handler
|
||||
sc := make(chan os.Signal, 1)
|
||||
|
@ -30,11 +28,15 @@ func main() {
|
|||
log.Println("Saving state and shutting down...")
|
||||
util.SaveCurrentState(*resp)
|
||||
os.Exit(0)
|
||||
}(&spaceApiResponse)
|
||||
}(&conf.Response)
|
||||
|
||||
// Register HTTP handlers
|
||||
http.HandleFunc("/", handlers.Root(&spaceApiResponse))
|
||||
http.HandleFunc("/state/open", handlers.StateOpen(config.BAUsername, config.BAPassword, &spaceApiResponse))
|
||||
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...")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue