mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-30 19:33:01 +00:00
* Add support for consistent documentation using markdownlint * Only run workflow during changes to markdown files * Fix more inconsistencies * Fixes to markdown under .github/ * More fixes * Apply suggestions from code review Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Fix typo in limiter docs * Add missing space before code-block * Add check for dead-links * Add write-good * Remove legacy README files * Fix glob for skipping .md files * Use paths-ignore instead --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1.7 KiB
1.7 KiB
id
id |
---|
etag |
ETag
ETag middleware for Fiber that lets caches be more efficient and save bandwidth, as a web server does not need to resend a full response if the content has not changed.
Signatures
func New(config ...Config) fiber.Handler
Examples
Import the middleware package that is part of the Fiber web framework
import (
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/etag"
)
After you initiate your Fiber app, you can use the following possibilities:
// Initialize default config
app.Use(etag.New())
// Get / receives Etag: "13-1831710635" in response header
app.Get("/", func(c fiber.Ctx) error {
return c.SendString("Hello, World!")
})
// Or extend your config for customization
app.Use(etag.New(etag.Config{
Weak: true,
}))
// Get / receives Etag: "W/"13-1831710635" in response header
app.Get("/", func(c fiber.Ctx) error {
return c.SendString("Hello, World!")
})
Config
Property | Type | Description | Default |
---|---|---|---|
Weak | bool |
Weak indicates that a weak validator is used. Weak etags are easy to generate but are less useful for comparisons. | false |
Next | func(fiber.Ctx) bool |
Next defines a function to skip this middleware when returned true. | nil |
Default Config
var ConfigDefault = Config{
Next: nil,
Weak: false,
}