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.

Table of Contents

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) error {
  2. err := ctx.SendString("Hello, World 👋!")
  3. if err != nil {
  4. return err
  5. }
  6. return nil
  7. }
  8. app.Get("/foo", timeout.New(handler, 5 * time.Second))