Skip to content

Commit

Permalink
Add health route (#86)
Browse files Browse the repository at this point in the history
Fixes #85
  • Loading branch information
ostcar authored Jul 23, 2020
1 parent 20386a6 commit ce94d13
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func New(s *autoupdate.Autoupdate, auth Authenticator) *Handler {
}
h.mux.Handle("/system/autoupdate", http2Only(h.autoupdate(h.complex)))
h.mux.Handle("/system/autoupdate/keys", http2Only(h.autoupdate(h.simple)))
h.mux.Handle("/system/autoupdate/health", http2Only(http.HandlerFunc(h.health)))
return h
}

Expand Down Expand Up @@ -100,6 +101,10 @@ func (h *Handler) simple(r *http.Request, uid int) (autoupdate.KeysBuilder, erro
return kb, nil
}

func (h *Handler) health(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"healthy": true}`)
}

// errHandleFunc is like a http.Handler, but has a error as return value.
//
// If the returned error implements the DefinedError interface, then the error
Expand Down
1 change: 1 addition & 0 deletions internal/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestHandlerTestURLs(t *testing.T) {
{"", http.StatusNotFound},
{"/system/autoupdate", http.StatusBadRequest},
{"/system/autoupdate/keys?user/1/name", http.StatusOK},
{"/system/autoupdate/health", http.StatusOK},
}

for _, tt := range tc {
Expand Down

0 comments on commit ce94d13

Please sign in to comment.