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 New(store Store) *Handler { return &Handler{store: store} }
|
||||||
|
|
||||||
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
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 {
|
if r.Method != http.MethodPost {
|
||||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
|
@ -59,7 +65,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("content-type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte("OK\n"))
|
w.Write([]byte("OK\n"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,13 @@ func TestHandler(t *testing.T) {
|
||||||
wantStatusCode int
|
wantStatusCode int
|
||||||
wantBody string
|
wantBody string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
name: "healthz",
|
||||||
|
httpMethod: http.MethodGet,
|
||||||
|
path: "/healthz",
|
||||||
|
wantStatusCode: http.StatusOK,
|
||||||
|
wantBody: "OK\n",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "method not allowed",
|
name: "method not allowed",
|
||||||
httpMethod: http.MethodGet,
|
httpMethod: http.MethodGet,
|
||||||
|
|
Loading…
Reference in New Issue