diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-06-13 12:54:28 +0200 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-06-13 13:01:26 +0200 |
commit | 9d5a2f9870e52bfc0fe6db8c27981f29d91dcb55 (patch) | |
tree | e3856fbbd1bc7c429472d950e7f1d46e5cf2fae3 /src/web.go | |
parent | c015034ba2e0bfd8464ae444792552a4b354eb0d (diff) | |
download | birdscan-9d5a2f9870e52bfc0fe6db8c27981f29d91dcb55.tar birdscan-9d5a2f9870e52bfc0fe6db8c27981f29d91dcb55.tar.zst birdscan-9d5a2f9870e52bfc0fe6db8c27981f29d91dcb55.zip |
Implement working State Machine
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)) } |