Source File
compress.go
Belonging Package
github.com/gofiber/fiber/v2/middleware/compress
package compressimport ()// New creates a new middleware handlerfunc ( ...Config) fiber.Handler {// Set default config:= configDefault(...)// Setup request handlersvar (= func( *fasthttp.RequestCtx) {}fasthttp.RequestHandler)// Setup compression algorithmswitch .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:// LevelDisabledreturn func( *fiber.Ctx) error {return .Next()}}// Return new handlerreturn func( *fiber.Ctx) error {// Don't execute middleware if Next returns trueif .Next != nil && .Next() {return .Next()}// Continue stackif := .Next(); != nil {return}// Compress response(.Context())// Return from handlerreturn 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. |