extract the landingpage out from the code to a variable
This commit is contained in:
parent
c49231374e
commit
f591467354
2 changed files with 10 additions and 9 deletions
15
main.go
15
main.go
|
@ -41,6 +41,13 @@ var (
|
||||||
mystromDurationCounterVec *prometheus.CounterVec
|
mystromDurationCounterVec *prometheus.CounterVec
|
||||||
mystromRequestsCounterVec *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() {
|
func main() {
|
||||||
|
|
||||||
|
@ -97,13 +104,7 @@ func main() {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte(`<html>
|
w.Write(landingPage)
|
||||||
<head><title>myStrom switch report Exporter</title></head>
|
|
||||||
<body>
|
|
||||||
<h1>myStrom Exporter</h1>
|
|
||||||
<p><a href='` + *metricsPath + `'>Metrics</a></p>
|
|
||||||
</body>
|
|
||||||
</html>`))
|
|
||||||
})
|
})
|
||||||
log.Infoln("Listening on address " + *listenAddress)
|
log.Infoln("Listening on address " + *listenAddress)
|
||||||
log.Fatal(http.ListenAndServe(*listenAddress, router))
|
log.Fatal(http.ListenAndServe(*listenAddress, router))
|
||||||
|
|
|
@ -15,8 +15,8 @@ const namespace = "mystrom"
|
||||||
type switchReport struct {
|
type switchReport struct {
|
||||||
Power float64 `json:"power"`
|
Power float64 `json:"power"`
|
||||||
WattPerSec float64 `json:"Ws"`
|
WattPerSec float64 `json:"Ws"`
|
||||||
Relay bool `json:relay`
|
Relay bool `json:"relay"`
|
||||||
Temperature float64 `json:"temperature`
|
Temperature float64 `json:"temperature"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Exporter struct {
|
type Exporter struct {
|
||||||
|
|
Loading…
Reference in a new issue