Gzip
O middleware Gzip comprime a response HTTP usando o esquema de compressão gzip.
Todo o middleware principal fica no pacote middleware:
import "github.com/labstack/echo/v5/middleware"e.Use(middleware.Gzip())Configuração customizada
Seção intitulada “Configuração customizada”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 },}))Configuração
Seção intitulada “Configuração”type GzipConfig struct { // Skipper defines a function to skip middleware. Skipper Skipper
// Level is the gzip compression level. // Optional. Default value -1. Level int
// MinLength is the length threshold before gzip compression is applied. // Optional. Default value 0. // // Most of the time the default is fine. Compressing a short response might increase // the transmitted data because of gzip's format overhead, and compression consumes // CPU and time on both server and client. Depending on your use case such a // threshold can be useful. MinLength int}Configuração padrão
Seção intitulada “Configuração padrão”// Effective defaults applied when fields are left unset.GzipConfig{ Skipper: DefaultSkipper, Level: -1, MinLength: 0,}