-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.go
31 lines (25 loc) · 918 Bytes
/
routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func (e *exporter) routes() http.Handler {
router := httprouter.New()
router.NotFound = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
})
router.Handler(http.MethodGet, *metricsPath, promhttp.HandlerFor(e.Reg, promhttp.HandlerOpts{}))
router.HandlerFunc(http.MethodGet, "/healthz", func(w http.ResponseWriter, r *http.Request) { http.Error(w, "OK", http.StatusOK) })
router.HandlerFunc(http.MethodGet, "/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>power-datacenter Exporter</title></head>
<body>
<h1>power-datacenter Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>
`))
})
return router
}