-
Notifications
You must be signed in to change notification settings - Fork 132
/
main.go
45 lines (41 loc) · 1.19 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
package main
import (
"flag"
"net/http"
"os"
"time"
log "github.com/Sirupsen/logrus"
"github.com/gorilla/handlers"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version"
)
var ready = false
var addr = flag.String("listen-address", ":8000", "The address to listen on for HTTP requests.")
func main() {
flag.Parse()
log.Info("Starting presentation-gitlab-k8s application..")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
hostname, _ := os.Hostname()
w.Write([]byte("Hello World!\n"))
w.Write([]byte("Hostname: " + hostname + "\n"))
w.Write([]byte("Version Info:\n"))
w.Write([]byte(version.Print("app") + "\n"))
})
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
if ready {
w.WriteHeader(http.StatusOK)
w.Write([]byte("200"))
} else {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("500"))
}
})
http.Handle("/metrics", promhttp.Handler())
go func() {
<-time.After(5 * time.Second)
ready = true
log.Info("Application is ready!")
}()
log.Info("Listen on " + *addr)
log.Fatal(http.ListenAndServe(*addr, handlers.LoggingHandler(os.Stdout, http.DefaultServeMux)))
}