succd: split out http server, daemon state, daemon controller

This improves the structure of the code, separating the data/control
interface out and then implementing the http interface as a user of this
interface.
This commit is contained in:
Serge Bazanski 2024-09-28 08:10:33 +02:00
parent 3ec6fd1d1b
commit 8f7ec7e141
5 changed files with 190 additions and 180 deletions

View file

@ -26,9 +26,9 @@ func main() {
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt)
d := daemon{
rpOn: true,
}
d := daemon{}
d.daemonState.rpOn = true
d.aboveRough.threshold = float64(flagPressureThresholdRough)
d.aboveHigh.threshold = float64(flagPressureThresholdHigh)
if flagFake {
@ -65,16 +65,10 @@ func main() {
}
}
http.HandleFunc("/", d.httpIndex)
http.HandleFunc("/favicon.png", d.httpFavicon)
http.HandleFunc("/stream", d.httpStream)
http.HandleFunc("/metrics", d.httpMetrics)
http.HandleFunc("/button/vent", d.httpButtonVent)
http.HandleFunc("/button/pumpdown", d.httpButtonPumpDown)
http.HandleFunc("/rp/on", d.httpRoughingPumpEnable)
http.HandleFunc("/rp/off", d.httpRoughingPumpDisable)
http.HandleFunc("/dp/on", d.httpDiffusionPumpEnable)
http.HandleFunc("/dp/off", d.httpDiffusionPumpDisable)
httpServer := httpServer{
d: &d,
}
httpServer.setupViews()
klog.Infof("Listening for HTTP at %s", flagListenHTTP)
go func() {