succd: httpServer -> webServer

This commit is contained in:
Serge Bazanski 2024-09-28 09:19:14 +02:00
parent f66afc0c8f
commit 42c9ae2fa7
2 changed files with 15 additions and 15 deletions

View file

@ -15,7 +15,7 @@ import (
"k8s.io/klog"
)
type httpServer struct {
type webServer struct {
d daemonController
}
@ -27,7 +27,7 @@ var (
favicon []byte
)
func (s *httpServer) viewFavicon(w http.ResponseWriter, r *http.Request) {
func (s *webServer) viewFavicon(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "image/png")
w.Write(favicon)
}
@ -100,7 +100,7 @@ type apiData struct {
// apiData returns the user data model for the current state of the system. If
// skipSystem is set, the System subset is ignored (saves system load, and is
// not being served via websockets).
func (s *httpServer) apiData(skipSystem bool) *apiData {
func (s *webServer) apiData(skipSystem bool) *apiData {
state := s.d.snapshot()
volts, mbar := state.pirani()
rough, high := state.vacuumStatus()
@ -137,7 +137,7 @@ func (s *httpServer) apiData(skipSystem bool) *apiData {
}
// httpIndex is the / view.
func (s *httpServer) viewIndex(w http.ResponseWriter, r *http.Request) {
func (s *webServer) viewIndex(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
@ -150,7 +150,7 @@ func (s *httpServer) viewIndex(w http.ResponseWriter, r *http.Request) {
// httpStream is the websocket clientwards data hose, returning a 10Hz update
// stream of pressure/voltage.
func (s *httpServer) viewStream(w http.ResponseWriter, r *http.Request) {
func (s *webServer) viewStream(w http.ResponseWriter, r *http.Request) {
c, err := websocket.Accept(w, r, nil)
if err != nil {
return
@ -177,7 +177,7 @@ func (s *httpServer) viewStream(w http.ResponseWriter, r *http.Request) {
}
// httpMetrics serves minimalistic Prometheus-compatible metrics.
func (s *httpServer) viewMetrics(w http.ResponseWriter, r *http.Request) {
func (s *webServer) viewMetrics(w http.ResponseWriter, r *http.Request) {
// TODO(q3k): also serve Go stuff using the actual Prometheus metrics client
// library.
// TODO(q3k): serve the rest of the data model
@ -188,35 +188,35 @@ func (s *httpServer) viewMetrics(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "sem_pressure_mbar %f\n", mbar)
}
func (s *httpServer) viewRoughingPumpEnable(w http.ResponseWriter, r *http.Request) {
func (s *webServer) viewRoughingPumpEnable(w http.ResponseWriter, r *http.Request) {
s.d.rpSet(true)
fmt.Fprintf(w, "succ on\n")
}
func (s *httpServer) viewRoughingPumpDisable(w http.ResponseWriter, r *http.Request) {
func (s *webServer) viewRoughingPumpDisable(w http.ResponseWriter, r *http.Request) {
s.d.rpSet(false)
fmt.Fprintf(w, "succ off\n")
}
func (s *httpServer) viewDiffusionPumpEnable(w http.ResponseWriter, r *http.Request) {
func (s *webServer) viewDiffusionPumpEnable(w http.ResponseWriter, r *http.Request) {
s.d.dpSet(true)
fmt.Fprintf(w, "deep succ on\n")
}
func (s *httpServer) viewDiffusionPumpDisable(w http.ResponseWriter, r *http.Request) {
func (s *webServer) viewDiffusionPumpDisable(w http.ResponseWriter, r *http.Request) {
s.d.dpSet(false)
fmt.Fprintf(w, "deep succ off\n")
}
func (s *httpServer) viewButtonPumpDown(w http.ResponseWriter, r *http.Request) {
func (s *webServer) viewButtonPumpDown(w http.ResponseWriter, r *http.Request) {
s.d.pumpDownPress()
}
func (s *httpServer) viewButtonVent(w http.ResponseWriter, r *http.Request) {
func (s *webServer) viewButtonVent(w http.ResponseWriter, r *http.Request) {
s.d.ventPress()
}
func (s *httpServer) setupViews() {
func (s *webServer) setupViews() {
http.HandleFunc("/", s.viewIndex)
http.HandleFunc("/favicon.png", s.viewFavicon)
http.HandleFunc("/stream", s.viewStream)

View file

@ -65,10 +65,10 @@ func main() {
}
}
httpServer := httpServer{
web := webServer{
d: &d,
}
httpServer.setupViews()
web.setupViews()
klog.Infof("Listening for HTTP at %s", flagListenHTTP)
go func() {