forked from tomcz/openldap_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
36 lines (29 loc) · 755 Bytes
/
server.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
32
33
34
35
36
package openldap_exporter
import (
"fmt"
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var commit string
var tag string
func GetVersion() string {
return fmt.Sprintf("%s (%s)", tag, commit)
}
func StartMetricsServer(bindAddr, metricsPath string) {
mux := http.NewServeMux()
mux.Handle(metricsPath, promhttp.Handler())
mux.HandleFunc("/version", showVersion)
err := http.ListenAndServe(bindAddr, mux)
if err != nil {
log.Fatal("http listener failed, error is:", err)
}
}
func showVersion(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
fmt.Fprintln(w, GetVersion())
}