1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-20 22:33:09 +00:00
Muhammed Efe Çetin 1188144d78
🎉 v3: init
2022-05-31 17:35:49 +03:00
..
2021-05-10 10:48:07 -04:00
v2
2020-09-13 11:20:11 +02:00
🎉 v3: init
2022-05-31 17:35:49 +03:00

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

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

Examples

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

import (
  "github.com/gofiber/fiber/v2"
  "github.com/gofiber/fiber/v2/middleware/timeout"
)

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

handler := func(ctx *fiber.Ctx) error {
	err := ctx.SendString("Hello, World 👋!")
	if err != nil {
		return err
	}
	return nil
}

app.Get("/foo", timeout.New(handler, 5 * time.Second))