From cb34fcf502d97265b16f3496a1cb3b0c558c4e73 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 9 Apr 2023 00:30:03 +0200 Subject: [PATCH] fix: .*/healthz and .*/readyz endpoints for HTTP server --- server.go | 3 ++- server_test.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index 2d72be7..680fe69 100644 --- a/server.go +++ b/server.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net/http" + "strings" "sync" "github.com/aws/aws-lambda-go/lambda" @@ -197,7 +198,7 @@ func (m *ServeMux) Serve(b *ResponseBuilder, r *RequestEnvelope) { // ServeHTTP dispatches the request to the handler whose // alexa intent matches the request URL. func (m *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.URL != nil && (r.URL.Path == "/healthz" || r.URL.Path == "/readyz") { + if r.URL != nil && (strings.HasSuffix(r.URL.Path, "/livez") || strings.HasSuffix(r.URL.Path, "/readyz")) { if _, err := w.Write([]byte("ok")); err != nil { m.logger.Debug("failed to write response") } diff --git a/server_test.go b/server_test.go index 515ea6f..778611a 100644 --- a/server_test.go +++ b/server_test.go @@ -35,7 +35,7 @@ func TestServer(t *testing.T) { func TestMuxServeHTTPProbes(t *testing.T) { mux := NewServerMux(log.New(nil, log.ConsoleFormat(), log.Info)) rw := httptest.NewRecorder() - u, _ := url.Parse("http://anything/healthz") + u, _ := url.Parse("http://anything.net/livez") r := &http.Request{Method: http.MethodGet, URL: u} mux.ServeHTTP(rw, r) @@ -46,7 +46,7 @@ func TestMuxServeHTTPProbes(t *testing.T) { assert.Contains(t, string(res), "ok") rw = httptest.NewRecorder() - u, _ = url.Parse("http://anything/readyz") + u, _ = url.Parse("http://anything.com/somethingelse/readyz") r = &http.Request{Method: http.MethodGet, URL: u} mux.ServeHTTP(rw, r)