Timeout

Timeout middleware for Fiber wraps a fiber.Handler with a timeout. If the handler takes longer than the given duration to return, the timeout error is set and forwarded to the centralized ErrorHandler.

Signatures

  1. func New(h fiber.Handler, t time.Duration) fiber.Handler

Examples

Import the middleware package that is part of the Fiber web framework

  1. import (
  2. "github.com/gofiber/fiber/v2"
  3. "github.com/gofiber/fiber/v2/middleware/timeout"
  4. )

After you initiate your Fiber app, you can use the following possibilities:

  1. handler := func(ctx *fiber.Ctx) {
  2. ctx.Send("Hello, World 👋!")
  3. }
  4. app.Get("/foo", timeout.New(handler, 5 * time.Second))