// vim: shiftwidth=4 tabstop=4 noexpandtab package main import ( "fmt" "log" "net/http" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" ) const ( APP_DATA = "/usr/share/birdscan" ) type webConfig struct { BindAddress string `json:"bind_address"` BindPort string `json:"bind_port"` } func runServer(cfg *webConfig) { router := chi.NewRouter() router.Use(middleware.Logger) router.Get("/", indexHandler) router.Get("/css/birdscan.css", cssHandler) 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)) } func indexHandler(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, fmt.Sprintf("%s/html/index.html", APP_DATA)) } func cssHandler(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, fmt.Sprintf("%s/css/birdscan.css", APP_DATA)) } func jsHandler(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, fmt.Sprintf("%s/js/birdscan.js", APP_DATA)) } func singlePictureHandler(w http.ResponseWriter, r *http.Request) { log.Println("Received request for a single picture") fmt.Fprintf(w, http.StatusText(http.StatusOK)) }