Consolidate OK handler

This commit is contained in:
Stephen McQuay 2018-03-08 14:08:37 -08:00
parent 73f15774d6
commit e92f902930
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5
3 changed files with 13 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import (
"os" "os"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"mcquay.me/hw"
"mcquay.me/metrics" "mcquay.me/metrics"
) )
@ -53,12 +54,10 @@ func main() {
code := codes[rand.Intn(len(codes))] code := codes[rand.Intn(len(codes))]
w.WriteHeader(code) w.WriteHeader(code)
})) }))
http.HandleFunc("/live", m.WrapFunc("/live", ok)) http.HandleFunc("/live", m.WrapFunc("/live", hw.OK))
http.HandleFunc("/ready", m.WrapFunc("/ready", ok)) http.HandleFunc("/ready", m.WrapFunc("/ready", hw.OK))
http.Handle("/metrics", promhttp.Handler()) http.Handle("/metrics", promhttp.Handler())
if err := http.ListenAndServe(":8080", nil); err != nil { if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatalf("listen and serve: %v", err) log.Fatalf("listen and serve: %v", err)
} }
} }
func ok(w http.ResponseWriter, req *http.Request) {}

View File

@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"mcquay.me/hw"
"mcquay.me/metrics" "mcquay.me/metrics"
) )
@ -88,6 +89,9 @@ func main() {
} }
})) }))
http.HandleFunc("/live", m.WrapFunc("/live", hw.OK))
http.HandleFunc("/ready", m.WrapFunc("/ready", hw.OK))
http.Handle("/metrics", promhttp.Handler()) http.Handle("/metrics", promhttp.Handler())
if err := http.ListenAndServe(":8081", nil); err != nil { if err := http.ListenAndServe(":8081", nil); err != nil {

6
hw.go Normal file
View File

@ -0,0 +1,6 @@
package hw
import "net/http"
// OK simply return 200
func OK(w http.ResponseWriter, req *http.Request) {}