Ir al contenido

Gzip

El middleware Gzip comprime la response HTTP usando el esquema de compresión gzip.

Todo el middleware principal reside en el paquete middleware:

import "github.com/labstack/echo/v5/middleware"
e.Use(middleware.Gzip())
e := echo.New()
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 5,
}))
e := echo.New()
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Skipper: func(c *echo.Context) bool {
return strings.Contains(c.Path(), "metrics") // change "metrics" to your own path
},
}))

GzipConfig · github.com/labstack/echo/v5@5196b9b

Las descripciones de los campos se generan a partir de comentarios del código fuente en inglés.

Campos del código fuente
CampoTipoDescripciónFuente
Skipper Skipper Skipper defines a function to skip middleware. L27
Level int Gzip compression level. Optional. Default value -1. L31
MinLength int Length threshold before gzip compression is applied. Optional. Default value 0. Most of the time you will not need to change the default. Compressing a short response might increase the transmitted data because of the gzip format overhead. Compressing the response will also consume CPU and time on the server and the client (for decompressing). Depending on your use case such a threshold might be useful. See also: https://webmasters.stackexchange.com/questions/31750/what-is-recommended-minimum-object-size-for-gzip-performance-benefits L44
Funciones del código fuente
TipoFuente
func Gzip() echo.MiddlewareFunc L59
func GzipWithConfig(config GzipConfig) echo.MiddlewareFunc L64
// Effective defaults applied when fields are left unset.
GzipConfig{
Skipper: DefaultSkipper,
Level: -1,
MinLength: 0,
}