diff --git a/cmd/gqgmcd/main.go b/cmd/gqgmcd/main.go index 6536e37b56529c741b98f8f9cad0646e0c23c31c..c1c415aebb52c9da3ad30f8fd3bceb38a090438c 100644 --- a/cmd/gqgmcd/main.go +++ b/cmd/gqgmcd/main.go @@ -13,6 +13,7 @@ import ( "log" "net/http" "path" + //"sync" "github.com/prometheus/client_golang/prometheus/promhttp" "gitlab.com/lyda/gqgmc/devices/geiger" @@ -21,7 +22,8 @@ import ( var addr = flag.String("listen-address", ":8080", "Address for HTTP requests.") var device = flag.String("device", "/dev/gqgmc", "Device for Geiger Counter.") var model = flag.String("model", "gqgmc", "Model of Geiger Counter.") -var templateDir = flag.String("template_dir", "templates", "Template directory.") +var templateDir = flag.String("template-dir", "templates", "Template directory.") +var staticDir = flag.String("static-dir", "static", "Static files directory.") type indexPage struct { Model string @@ -44,6 +46,11 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { t.Execute(w, &indexPg) } +func staticHandler(w http.ResponseWriter, r *http.Request) { + staticFile := path.Join(*staticDir, path.Base(r.URL.Path)) + http.ServeFile(w, r, staticFile) +} + func main() { flag.Parse() @@ -52,6 +59,10 @@ func main() { indexPg.Version = gc.Version() indexPg.Serial = gc.Serial() http.HandleFunc("/", indexHandler) + http.HandleFunc("/favicon.ico", staticHandler) + http.HandleFunc("/robots.txt", staticHandler) + http.HandleFunc("/humans.txt", staticHandler) http.Handle("/metrics", promhttp.Handler()) + http.Handle("/static", http.StripPrefix("/static/", http.FileServer(http.Dir(*staticDir)))) log.Fatal(http.ListenAndServe(*addr, nil)) } diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..9a59519a3ec438437e563d01b0e43694f13d918b Binary files /dev/null and b/static/favicon.ico differ diff --git a/static/humans.txt b/static/humans.txt new file mode 100644 index 0000000000000000000000000000000000000000..55028f574f40a28b90815e6d49199f32608ad9d3 --- /dev/null +++ b/static/humans.txt @@ -0,0 +1,17 @@ +/* TEAM */ + +TODO +Your title: Your name. +Site: email, link to a contact form, etc. +Twitter: your Twitter username. +Location: City, Country. + +/* THANKS */ + +TODO + +/* SITE */ + +Standards: Let me know if things aren't valid HTML/CSS/JS +Components: Go, Prometheus +Software: Developed using Linux, vim and git. diff --git a/static/robots.txt b/static/robots.txt new file mode 100644 index 0000000000000000000000000000000000000000..2bf371c29a04931c9ce617cdff7732bf4e97785a --- /dev/null +++ b/static/robots.txt @@ -0,0 +1,3 @@ +User-Agent: * +Disallow: +Disallow: /metrics