Skip to content

Commit

Permalink
📝 docs: move docs to middleware session
Browse files Browse the repository at this point in the history
  • Loading branch information
luk3skyw4lker committed Jun 30, 2023
1 parent ef1e265 commit df23f68
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 26 deletions.
27 changes: 1 addition & 26 deletions docs/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
75 changes: 75 additions & 0 deletions docs/api/middleware/probechecker.md
Original file line number Diff line number Diff line change
@@ -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
}
```

0 comments on commit df23f68

Please sign in to comment.