Skip to content

Commit 6ab97fe

Browse files
committed
feat: Add healthz endpoint for kubernetes liveness probe
1 parent 7e656d1 commit 6ab97fe

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

cmd/plaincooking/wire.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func InjectServer() (*http.Server, error) {
2222
web.NewAssetController,
2323
web.NewRecipeController,
2424
web.NewSessionController,
25+
web.NewProbeController,
2526

2627
// OpenID Connect
2728
oidc.NewProvider,

internal/web/controller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,18 @@ func (c *AssetController) reader(ctx echo.Context, req DownloadAssetRequest) (*s
350350

351351
return c.assets.Reader(ctx.Request().Context(), req.ID)
352352
}
353+
354+
type ProbeController struct{}
355+
356+
func NewProbeController() *ProbeController {
357+
return &ProbeController{}
358+
}
359+
360+
// @summary Check service health
361+
// @id healthProbe
362+
// @tags probes
363+
// @router /healthz [get]
364+
// @success 200
365+
func (c *ProbeController) Health(ctx echo.Context) error {
366+
return ctx.NoContent(http.StatusOK)
367+
}

internal/web/router.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func NewRouter(
2020
sessions *SessionController,
2121
assets *AssetController,
2222
recipes *RecipeController,
23+
probes *ProbeController,
2324
) http.Handler {
2425
r := echo.New()
2526
r.Binder = new(binder)
@@ -42,6 +43,7 @@ func NewRouter(
4243
api := r.Group("/api")
4344
api.Use(transactional(transactions))
4445

46+
api.GET("/healthz", probes.Health)
4547
api.GET("/session/info", sessions.UserInfo, oidcSession.Require)
4648

4749
api.GET("/recipes", recipes.List)

0 commit comments

Comments
 (0)