Skip to content

Commit

Permalink
adds new healthz endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinGallauner committed May 9, 2024
1 parent 577a9d4 commit 8b05856
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
6 changes: 5 additions & 1 deletion http/bookclub.http
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ GET http://localhost:8080/auth/google
###
# group: auth
# @name logout
GET http://localhost:8080/auth/google/logout
GET http://localhost:8080/auth/google/logout

###
# @name healthz
GET http://localhost:8080/api/healthz
9 changes: 9 additions & 0 deletions internal/handler_readiness.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package internal

import "net/http"

func handlerReadiness(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(http.StatusText(http.StatusOK)))
}
7 changes: 4 additions & 3 deletions internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ func NewBookclubServer(client Client, repository BookRepository, userRepository
router.Handle("/api/users", http.HandlerFunc(s.handlerCreateUser))
router.Handle("/api/links/{id}", http.HandlerFunc(s.handlerGetLinks))
router.Handle("/api/links", http.HandlerFunc(s.handlerCreateLink))
router.Handle("/auth/{provider}/callback", http.HandlerFunc(s.handlerCallback))
router.Handle("/auth/{provider}/logout", http.HandlerFunc(s.handlerLogout))
router.Handle("/auth/{provider}", http.HandlerFunc(s.handlerLogin))
router.Handle("/api/auth/{provider}/callback", http.HandlerFunc(s.handlerCallback))
router.Handle("/api/auth/{provider}/logout", http.HandlerFunc(s.handlerLogout))
router.Handle("/api/auth/{provider}", http.HandlerFunc(s.handlerLogin))
router.Handle("/swagger/*", httpSwagger.Handler(httpSwagger.URL("http://localhost:8080/swagger/doc.json")))
router.Handle("/api/healthz", http.HandlerFunc(handlerReadiness))

s.Handler = router
return s
Expand Down
4 changes: 2 additions & 2 deletions internal/user_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestLogin(t *testing.T) {

//when

request, _ := http.NewRequest(http.MethodPost, "/auth/login", nil)
request, _ := http.NewRequest(http.MethodPost, "/api/auth/login", nil)
response := httptest.NewRecorder()
s.ServeHTTP(response, request)

Expand Down Expand Up @@ -213,7 +213,7 @@ func TestLoginOfNewUser(t *testing.T) {
}

//when
request, _ := http.NewRequest(http.MethodPost, "/auth/login", nil)
request, _ := http.NewRequest(http.MethodPost, "/api/auth/login", nil)
response := httptest.NewRecorder()
s.ServeHTTP(response, request)

Expand Down

0 comments on commit 8b05856

Please sign in to comment.