handler: Add health check
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-07-13 21:36:38 +02:00
parent f70fc1d266
commit 731652dcb3
2 changed files with 13 additions and 1 deletions

View File

@ -22,6 +22,12 @@ type Handler struct {
func New(store Store) *Handler { return &Handler{store: store} }
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet && r.URL.Path == "/healthz" {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK\n"))
return
}
if r.Method != http.MethodPost {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
@ -59,7 +65,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK\n"))
}

View File

@ -32,6 +32,13 @@ func TestHandler(t *testing.T) {
wantStatusCode int
wantBody string
}{
{
name: "healthz",
httpMethod: http.MethodGet,
path: "/healthz",
wantStatusCode: http.StatusOK,
wantBody: "OK\n",
},
{
name: "method not allowed",
httpMethod: http.MethodGet,