Skip to content

Commit 9266003

Browse files
committed
Add /healthz route
1 parent a861ed0 commit 9266003

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

api/api.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func New(options *Options) *API {
5252
httpapi.WriteBytes(rw, http.StatusOK, []byte("Marketplace is running"))
5353
})
5454

55+
r.Get("/healthz", func(rw http.ResponseWriter, r *http.Request) {
56+
httpapi.WriteBytes(rw, http.StatusOK, []byte("API server running"))
57+
})
58+
5559
return &API{
5660
Handler: r,
5761
}

api/api_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ func TestServer(t *testing.T) {
3131
resp, err = http.Get(server.URL)
3232
require.NoError(t, err)
3333
require.Equal(t, http.StatusOK, resp.StatusCode)
34+
35+
resp, err = http.Get(server.URL + "/healthz")
36+
require.NoError(t, err)
37+
require.Equal(t, http.StatusOK, resp.StatusCode)
3438
}

api/httpmw/logger.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ func Logger(log slog.Logger) func(next http.Handler) http.Handler {
2121

2222
next.ServeHTTP(sw, r)
2323

24+
// Do not log successful health check requests.
25+
if r.URL.Path == "/healthz" && sw.Status == 200 {
26+
return
27+
}
28+
2429
httplog = httplog.With(
2530
slog.F("took", time.Since(start)),
2631
slog.F("status_code", sw.Status),

0 commit comments

Comments
 (0)