From df23f6871fe906ed6dbe28ca85bbdcf285d8f00a Mon Sep 17 00:00:00 2001 From: luk3skyw4lker Date: Fri, 30 Jun 2023 19:45:44 -0300 Subject: [PATCH] :memo: docs: move docs to middleware session --- docs/api/app.md | 27 +---------- docs/api/middleware/probechecker.md | 75 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 26 deletions(-) create mode 100644 docs/api/middleware/probechecker.md diff --git a/docs/api/app.md b/docs/api/app.md index fb55ad3c66..dd0e97dc20 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -654,29 +654,4 @@ Hooks is a method to return [hooks](../guide/hooks.md) property. ```go title="Signature" func (app *App) Hooks() *Hooks -``` - -## Liveness And Readiness Checks - -Fiber comes with an out of the box way of implementing your liveness and readiness checking, when creating a new app, you can pass your own handlers for liveness and readiness checks: - -```go title="Examples" -// Create route with GET method for test: -app := fiber.New(fiber.Config{ - IsLive: func (c *fiber.Ctx) bool { - return true - }, - IsLiveEndpoint: "/livez", - IsReady: func (c *fiber.Ctx) bool { - return serviceA.Ready() && serviceB.Ready() && ... - } - IsReadyEndpoint: "/readyz", -}) - -// Listen on port :8080 -app.Listen(":8080") -``` - -The endpoint values default to `/livez` for liveness and `/readyz` for readiness. Both functions are optional, the liveness endpoint will return `true` right when the server is up and running but the readiness endpoint will not answer any requests if an `IsReady` function isn't provided. - -The HTTP status returned to the containerized environment are: 200 OK if the checker function returns true and 503 Service Unavailable if the checker function returns false. \ No newline at end of file +``` \ No newline at end of file diff --git a/docs/api/middleware/probechecker.md b/docs/api/middleware/probechecker.md new file mode 100644 index 0000000000..510ba46d31 --- /dev/null +++ b/docs/api/middleware/probechecker.md @@ -0,0 +1,75 @@ +--- +id: probecheker +title: probecheker +--- + +Liveness and readiness probes middleware for [Fiber](https://github.com/gofiber/fiber) that provides two endpoints for checking the health and ready state of any HTTP application. + +The endpoint values default to `/livez` for liveness and `/readyz` for readiness. Both functions are optional, the liveness endpoint will return `true` right when the server is up and running but the readiness endpoint will not answer any requests if an `IsReady` function isn't provided. + +The HTTP status returned to the containerized environment are: 200 OK if the checker function returns true and 503 Service Unavailable if the checker function returns false. + +## Signatures + +```go +func New() fiber.Handler +``` + +## Examples + +Import the middleware package that is part of the Fiber web framework + +```go +import ( + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/probechecker" +) +``` + +After you initiate your Fiber app, you can use the following possibilities: + +```go +// Initializing with default config +app.Use(probechecker.New()) + +// Initialize with custom config +app.Use( + probechecker.New( + IsLive: func (c *fiber.Ctx) bool { + return true + }, + IsLiveEndpoint: "/livez", + IsReady: func (c *fiber.Ctx) bool { + return serviceA.Ready() && serviceB.Ready() && ... + } + IsReadyEndpoint: "/readyz", + ) +) + +``` + +## Config + +```go +type Config struct { + // Config for liveness probe of the container engine being used + // + // Optional. Default: func(c *Ctx) bool { return true } + IsLive ProbeChecker + + // HTTP endpoint of the liveness probe + // + // Optional. Default: /livez + IsLiveEndpoint string + + // Config for readiness probe of the container engine being used + // + // Optional. Default: nil + IsReady ProbeChecker + + // HTTP endpoint of the readiness probe + // + // Optional. Default: /readyz + IsReadyEndpoint string +} +``` \ No newline at end of file