Create a library for serving static files
It serves files that are in a given directory, and this could be
extended to html files.
In order to validate the functionality we also added a simple
`ScoutingServer` that you can `Start()` and `Stop()`. The unit test
makes use of this. The `main` binary that ties all the components
together also makes use of this.
See the README for an overview of everything we added in this patch.
Change-Id: Id496b032d6aa70fd8502eeb347895ac52b5d1ddd
Signed-off-by: Het Satasiya <satasiyahet@gmail.com>
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
diff --git a/scouting/webserver/main.go b/scouting/webserver/main.go
new file mode 100644
index 0000000..aebeef9
--- /dev/null
+++ b/scouting/webserver/main.go
@@ -0,0 +1,33 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "os/signal"
+ "syscall"
+
+ "github.com/frc971/971-Robot-Code/scouting/webserver/server"
+ "github.com/frc971/971-Robot-Code/scouting/webserver/static"
+)
+
+func main() {
+ portPtr := flag.Int("port", 8080, "The port number to bind to.")
+ dirPtr := flag.String("directory", ".", "The directory to serve at /.")
+ flag.Parse()
+
+ scoutingServer := server.NewScoutingServer()
+ static.ServePages(scoutingServer, *dirPtr)
+ scoutingServer.Start(*portPtr)
+ fmt.Println("Serving", *dirPtr, "on port", *portPtr)
+
+ // Block until the user hits Ctrl-C.
+ sigint := make(chan os.Signal, 1)
+ signal.Notify(sigint, syscall.SIGINT)
+ fmt.Println("Waiting for CTRL-C or SIGINT.")
+ <-sigint
+
+ fmt.Println("Shutting down.")
+ scoutingServer.Stop()
+ fmt.Println("Successfully shut down.")
+}