succd: httpServer -> webServer
This commit is contained in:
parent
f66afc0c8f
commit
42c9ae2fa7
|
@ -15,7 +15,7 @@ import (
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type httpServer struct {
|
type webServer struct {
|
||||||
d daemonController
|
d daemonController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ var (
|
||||||
favicon []byte
|
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.Header().Set("Content-Type", "image/png")
|
||||||
w.Write(favicon)
|
w.Write(favicon)
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ type apiData struct {
|
||||||
// apiData returns the user data model for the current state of the system. If
|
// 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
|
// skipSystem is set, the System subset is ignored (saves system load, and is
|
||||||
// not being served via websockets).
|
// not being served via websockets).
|
||||||
func (s *httpServer) apiData(skipSystem bool) *apiData {
|
func (s *webServer) apiData(skipSystem bool) *apiData {
|
||||||
state := s.d.snapshot()
|
state := s.d.snapshot()
|
||||||
volts, mbar := state.pirani()
|
volts, mbar := state.pirani()
|
||||||
rough, high := state.vacuumStatus()
|
rough, high := state.vacuumStatus()
|
||||||
|
@ -137,7 +137,7 @@ func (s *httpServer) apiData(skipSystem bool) *apiData {
|
||||||
}
|
}
|
||||||
|
|
||||||
// httpIndex is the / view.
|
// 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 != "/" {
|
if r.URL.Path != "/" {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
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
|
// httpStream is the websocket clientwards data hose, returning a 10Hz update
|
||||||
// stream of pressure/voltage.
|
// 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)
|
c, err := websocket.Accept(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -177,7 +177,7 @@ func (s *httpServer) viewStream(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// httpMetrics serves minimalistic Prometheus-compatible metrics.
|
// 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
|
// TODO(q3k): also serve Go stuff using the actual Prometheus metrics client
|
||||||
// library.
|
// library.
|
||||||
// TODO(q3k): serve the rest of the data model
|
// 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)
|
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)
|
s.d.rpSet(true)
|
||||||
fmt.Fprintf(w, "succ on\n")
|
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)
|
s.d.rpSet(false)
|
||||||
fmt.Fprintf(w, "succ off\n")
|
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)
|
s.d.dpSet(true)
|
||||||
fmt.Fprintf(w, "deep succ on\n")
|
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)
|
s.d.dpSet(false)
|
||||||
fmt.Fprintf(w, "deep succ off\n")
|
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()
|
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()
|
s.d.ventPress()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) setupViews() {
|
func (s *webServer) setupViews() {
|
||||||
http.HandleFunc("/", s.viewIndex)
|
http.HandleFunc("/", s.viewIndex)
|
||||||
http.HandleFunc("/favicon.png", s.viewFavicon)
|
http.HandleFunc("/favicon.png", s.viewFavicon)
|
||||||
http.HandleFunc("/stream", s.viewStream)
|
http.HandleFunc("/stream", s.viewStream)
|
||||||
|
|
|
@ -65,10 +65,10 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpServer := httpServer{
|
web := webServer{
|
||||||
d: &d,
|
d: &d,
|
||||||
}
|
}
|
||||||
httpServer.setupViews()
|
web.setupViews()
|
||||||
|
|
||||||
klog.Infof("Listening for HTTP at %s", flagListenHTTP)
|
klog.Infof("Listening for HTTP at %s", flagListenHTTP)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
Loading…
Reference in a new issue