Commit c4a8662d authored by Kevin Lyda's avatar Kevin Lyda 💬
Browse files

Add some static files.

parent 034506ec
Pipeline #1225 passed with stage
in 1 minute and 12 seconds
......@@ -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))
}
/* 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.
User-Agent: *
Disallow:
Disallow: /metrics
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment