Skip to content

Commit 249f4d0

Browse files
committed
add health check endpoint
1 parent 10a9e53 commit 249f4d0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ relay serve --port 8080 --ttl 30s --strategy fifo
166166
The API can be consumed by the vendor's application to claim and release a
167167
license on behalf of a node.
168168

169+
#### Health Check
170+
171+
The Relay server's health can be tested with the following endpoint:
172+
173+
```bash
174+
curl -v -X GET "http://localhost:6349/v1/health"
175+
```
176+
177+
Returns a `200 OK` status code.
178+
169179
#### Claim license
170180

171181
Nodes can claim a license by sending a `PUT` request to the

internal/server/handler.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package server
22

33
import (
44
"encoding/json"
5-
"github.com/gorilla/mux"
6-
"github.com/keygen-sh/keygen-relay/internal/licenses"
75
"log/slog"
86
"net/http"
7+
8+
"github.com/gorilla/mux"
9+
"github.com/keygen-sh/keygen-relay/internal/licenses"
910
)
1011

1112
type RequestBodyPayload struct {
@@ -33,10 +34,15 @@ func NewHandler(m licenses.Manager) Handler {
3334
}
3435

3536
func (h *handler) RegisterRoutes(r *mux.Router) {
37+
r.HandleFunc("/v1/health", h.HealthCheck).Methods("GET")
3638
r.HandleFunc("/v1/nodes/{fingerprint}", h.ClaimLicense).Methods("PUT")
3739
r.HandleFunc("/v1/nodes/{fingerprint}", h.ReleaseLicense).Methods("DELETE")
3840
}
3941

42+
func (h *handler) HealthCheck(w http.ResponseWriter, r *http.Request) {
43+
w.WriteHeader(http.StatusOK)
44+
}
45+
4046
func (h *handler) ClaimLicense(w http.ResponseWriter, r *http.Request) {
4147
fingerprint := mux.Vars(r)["fingerprint"]
4248

0 commit comments

Comments
 (0)