Handle webserver requests from the scouting web page
Right now we don't actually serve a whole lot. It's mostly the
infrastructure. I added a simple data scouting submission as an
example. We can build up from there.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I0572a214039cdb61e5bddf6f7256955a06147099
diff --git a/scouting/webserver/server/server.go b/scouting/webserver/server/server.go
index ff85794..c21e2a1 100644
--- a/scouting/webserver/server/server.go
+++ b/scouting/webserver/server/server.go
@@ -17,6 +17,9 @@
// Add a handler for a particular path. See upstream docs for this:
// https://pkg.go.dev/net/http#ServeMux.Handle
Handle(string, http.Handler)
+ // Add a handler function for a particular path. See upstream docs:
+ // https://pkg.go.dev/net/http#ServeMux.HandleFunc
+ HandleFunc(string, func(http.ResponseWriter, *http.Request))
// Starts the server on the specified port. Handlers cannot be added
// once this function is called.
Start(int)
@@ -54,6 +57,13 @@
server.mux.Handle(path, handler)
}
+func (server *scoutingServer) HandleFunc(path string, handler func(http.ResponseWriter, *http.Request)) {
+ if server.started {
+ log.Fatal("Cannot add handlers once server has started.")
+ }
+ server.mux.HandleFunc(path, handler)
+}
+
func (server *scoutingServer) Start(port int) {
if server.started {
log.Fatal("Cannot Start() a server a second time.")