extract the landingpage out from the code to a variable

This commit is contained in:
Andre Kully 2021-12-23 16:48:29 +01:00
parent c49231374e
commit f591467354
2 changed files with 10 additions and 9 deletions

15
main.go
View file

@ -41,6 +41,13 @@ var (
mystromDurationCounterVec *prometheus.CounterVec
mystromRequestsCounterVec *prometheus.CounterVec
)
var landingPage = []byte(`<html>
<head><title>myStrom switch report Exporter</title></head>
<body>
<h1>myStrom Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`)
func main() {
@ -97,13 +104,7 @@ func main() {
}),
)
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>myStrom switch report Exporter</title></head>
<body>
<h1>myStrom Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
w.Write(landingPage)
})
log.Infoln("Listening on address " + *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, router))

View file

@ -15,8 +15,8 @@ const namespace = "mystrom"
type switchReport struct {
Power float64 `json:"power"`
WattPerSec float64 `json:"Ws"`
Relay bool `json:relay`
Temperature float64 `json:"temperature`
Relay bool `json:"relay"`
Temperature float64 `json:"temperature"`
}
type Exporter struct {