Source File
compress.go
Belonging Package
github.com/gofiber/fiber/v2/middleware/compress
package compress
import (
)
// New creates a new middleware handler
func ( ...Config) fiber.Handler {
// Set default config
:= configDefault(...)
// Setup request handlers
var (
= func( *fasthttp.RequestCtx) {}
fasthttp.RequestHandler
)
// Setup compression algorithm
switch .Level {
case LevelDefault:
// LevelDefault
= fasthttp.CompressHandlerBrotliLevel(,
fasthttp.CompressBrotliDefaultCompression,
fasthttp.CompressDefaultCompression,
)
case LevelBestSpeed:
// LevelBestSpeed
= fasthttp.CompressHandlerBrotliLevel(,
fasthttp.CompressBrotliBestSpeed,
fasthttp.CompressBestSpeed,
)
case LevelBestCompression:
// LevelBestCompression
= fasthttp.CompressHandlerBrotliLevel(,
fasthttp.CompressBrotliBestCompression,
fasthttp.CompressBestCompression,
)
default:
// LevelDisabled
return func( *fiber.Ctx) error {
return .Next()
}
}
// Return new handler
return func( *fiber.Ctx) error {
// Don't execute middleware if Next returns true
if .Next != nil && .Next() {
return .Next()
}
// Continue stack
if := .Next(); != nil {
return
}
// Compress response
(.Context())
// Return from handler
return nil
}
}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |