From e92f90293081b425d44dddc4f63bd64615c16061 Mon Sep 17 00:00:00 2001 From: "Stephen McQuay (smcquay)" Date: Thu, 8 Mar 2018 14:08:37 -0800 Subject: [PATCH] Consolidate OK handler --- cmd/hw/main.go | 7 +++---- cmd/hwc/main.go | 4 ++++ hw.go | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 hw.go diff --git a/cmd/hw/main.go b/cmd/hw/main.go index 14fd41d..6398684 100644 --- a/cmd/hw/main.go +++ b/cmd/hw/main.go @@ -9,6 +9,7 @@ import ( "os" "github.com/prometheus/client_golang/prometheus/promhttp" + "mcquay.me/hw" "mcquay.me/metrics" ) @@ -53,12 +54,10 @@ func main() { code := codes[rand.Intn(len(codes))] w.WriteHeader(code) })) - http.HandleFunc("/live", m.WrapFunc("/live", ok)) - http.HandleFunc("/ready", m.WrapFunc("/ready", ok)) + http.HandleFunc("/live", m.WrapFunc("/live", hw.OK)) + http.HandleFunc("/ready", m.WrapFunc("/ready", hw.OK)) http.Handle("/metrics", promhttp.Handler()) if err := http.ListenAndServe(":8080", nil); err != nil { log.Fatalf("listen and serve: %v", err) } } - -func ok(w http.ResponseWriter, req *http.Request) {} diff --git a/cmd/hwc/main.go b/cmd/hwc/main.go index 60a57c3..e7dd9c4 100644 --- a/cmd/hwc/main.go +++ b/cmd/hwc/main.go @@ -10,6 +10,7 @@ import ( "time" "github.com/prometheus/client_golang/prometheus/promhttp" + "mcquay.me/hw" "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()) if err := http.ListenAndServe(":8081", nil); err != nil { diff --git a/hw.go b/hw.go new file mode 100644 index 0000000..de991e1 --- /dev/null +++ b/hw.go @@ -0,0 +1,6 @@ +package hw + +import "net/http" + +// OK simply return 200 +func OK(w http.ResponseWriter, req *http.Request) {}