diff options
Diffstat (limited to 'src/web.go')
-rw-r--r-- | src/web.go | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -15,12 +15,22 @@ const ( APP_DATA = "/usr/share/birdscan" ) +type WebServer struct { + config *webConfig +} + type webConfig struct { BindAddress string `json:"bind_address"` BindPort string `json:"bind_port"` } -func runServer(cfg *webConfig) { +func NewWebServer(cfg *webConfig) WebServer { + server := WebServer{} + server.config = cfg + return server +} + +func (server *WebServer) run() { router := chi.NewRouter() router.Use(middleware.Logger) @@ -29,8 +39,8 @@ func runServer(cfg *webConfig) { router.Get("/js/birdscan.js", jsHandler) router.Post("/api/single_picture", singlePictureHandler) - log.Println("Binding to 'http://" + cfg.BindAddress + ":" + cfg.BindPort + "'") - log.Fatal(http.ListenAndServe(cfg.BindAddress + ":" + cfg.BindPort, router)) + log.Println("Binding to 'http://" + server.config.BindAddress + ":" + server.config.BindPort + "'") + log.Fatal(http.ListenAndServe(server.config.BindAddress + ":" + server.config.BindPort, router)) } func indexHandler(w http.ResponseWriter, r *http.Request) { @@ -47,6 +57,7 @@ func jsHandler(w http.ResponseWriter, r *http.Request) { func singlePictureHandler(w http.ResponseWriter, r *http.Request) { log.Println("Received request for a single picture") + camera.SendEvent("take_single_picture") fmt.Fprintf(w, http.StatusText(http.StatusOK)) } |