Commit 2f99e79b authored by Kevin Lyda's avatar Kevin Lyda 💬

Initial pass at templates.

parent 6605c92a
Pipeline #1220 passed with stage
in 1 minute and 23 seconds
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Geiger Counter</title>
</head>
<body>
<ul>
<li>Model: {{.Model}}</li>
<li>Version: {{.Version}}</li>
<li>Serial: {{.Serial}}</li>
<li>Volts: {{.Volts}}</li>
<li>CPM: {{.CPM}}</li>
</ul>
</body>
</html>
......@@ -9,22 +9,44 @@ package main
import (
"flag"
"fmt"
"html/template"
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gitlab.com/lyda/gqgmc/devices/geiger"
)
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.")
func metricsHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Some metrics.")
type indexPage struct {
Model string
Version string
Serial string
Volts int16
CPM uint16
}
var gc geiger.Counter
var indexPg indexPage
func indexHandler(w http.ResponseWriter, r *http.Request) {
indexPg.CPM, _ = gc.GetCPM()
t, _ := template.ParseFiles("index.html")
t.Execute(w, indexPg)
}
func main() {
flag.Parse()
http.HandleFunc("/", metricsHandler)
gc, _ = geiger.New(geiger.Config{Model: *model, Device: *device})
indexPg.Model = gc.Model()
indexPg.Version = gc.Version()
indexPg.Serial, _ = gc.SerialNum()
indexPg.Volts, _ = gc.Volts()
http.HandleFunc("/", indexHandler)
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(*addr, nil))
}
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