handler: Add health check
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f70fc1d266
commit
731652dcb3
|
@ -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"))
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue