diff --git a/README.md b/README.md index 1e916cf..6139a7e 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ See the [GoDoc examples](https://godoc.org/github.com/heptiolabs/healthcheck) fo - Create a `healthcheck.Handler`: ```go - health := healthcheck.NewHandler() + health := healthcheck.NewHandler("", "") ``` - Configure some application-specific liveness checks (whether the app itself is unhealthy): diff --git a/example_test.go b/example_test.go index 245c6c2..c8f477e 100644 --- a/example_test.go +++ b/example_test.go @@ -31,7 +31,7 @@ import ( func Example() { // Create a Handler that we can use to register liveness and readiness checks. - health := NewHandler() + health := NewHandler("", "") // Add a readiness check to make sure an upstream dependency resolves in DNS. // If this fails we don't want to receive requests, but we shouldn't be @@ -65,7 +65,7 @@ func Example_database() { database = connectToDatabase() // Create a Handler that we can use to register liveness and readiness checks. - health := NewHandler() + health := NewHandler("", "") // Add a readiness check to we don't receive requests unless we can reach // the database with a ping in <1 second. @@ -89,7 +89,7 @@ func Example_database() { func Example_advanced() { // Create a Handler that we can use to register liveness and readiness checks. - health := NewHandler() + health := NewHandler("", "") // Make sure we can connect to an upstream dependency over TCP in less than // 50ms. Run this check asynchronously in the background every 10 seconds diff --git a/handler.go b/handler.go index 6ea9740..716e127 100644 --- a/handler.go +++ b/handler.go @@ -29,13 +29,22 @@ type basicHandler struct { } // NewHandler creates a new basic Handler -func NewHandler() Handler { +func NewHandler(liveURL string, readyURL string) Handler { h := &basicHandler{ livenessChecks: make(map[string]Check), readinessChecks: make(map[string]Check), } - h.Handle("/live", http.HandlerFunc(h.LiveEndpoint)) - h.Handle("/ready", http.HandlerFunc(h.ReadyEndpoint)) + + if liveURL == "" { + liveURL = "/live" + } + + if readyURL == "" { + readyURL = "/ready" + } + + h.Handle(liveURL, http.HandlerFunc(h.LiveEndpoint)) + h.Handle(readyURL, http.HandlerFunc(h.ReadyEndpoint)) return h } diff --git a/handler_test.go b/handler_test.go index 2e894b4..22dffff 100644 --- a/handler_test.go +++ b/handler_test.go @@ -123,7 +123,7 @@ func TestNewHandler(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - h := NewHandler() + h := NewHandler("", "") if !tt.live { h.AddLivenessCheck("test-liveness-check", func() error { diff --git a/metrics_handler.go b/metrics_handler.go index e95be0f..27c403b 100644 --- a/metrics_handler.go +++ b/metrics_handler.go @@ -30,7 +30,7 @@ type metricsHandler struct { // into the provided Prometheus registry. func NewMetricsHandler(registry prometheus.Registerer, namespace string) Handler { return &metricsHandler{ - handler: NewHandler(), + handler: NewHandler("", ""), registry: registry, namespace: namespace, }