-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
50 lines (39 loc) · 1.09 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
var (
port = "9805"
)
func init() {
log.SetFormatter(&log.JSONFormatter{})
}
func hcHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
if _, err := w.Write([]byte("healthy")); err != nil {
log.Error("error in path '/': " + err.Error())
}
}
func debugHandler(w http.ResponseWriter, r *http.Request) {
target, ok := r.URL.Query()["debug"]
if !ok || len(target[0]) < 1 || target[0] != "on" {
log.SetLevel(log.InfoLevel)
} else {
log.SetLevel(log.DebugLevel)
}
w.WriteHeader(http.StatusOK)
if _, err := w.Write([]byte("healthy")); err != nil {
log.Error("error in path '/debug': " + err.Error())
}
}
func main() {
// The Handler function provides a default handler to expose metrics
// via an HTTP server.
http.Handle("/trace", traceMiddleware(promhttp.Handler()))
http.HandleFunc("/", hcHandler)
http.HandleFunc("/debug", debugHandler)
log.Info("Listening on port: ", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}