Documentation ¶
Index ¶
- Constants
- func Compress(opts ...CompressOption) gin.HandlerFunc
- type CompressOption
- func WithAlgo(algo string, enable bool) CompressOption
- func WithCompressLevel(algo string, level int) CompressOption
- func WithDecompressBody(decompress bool) CompressOption
- func WithExcludeFunc(f func(c *gin.Context) bool) CompressOption
- func WithMaxDecodeSteps(steps int) CompressOption
- func WithMinCompressBytes(numBytes int) CompressOption
- func WithPriority(algo string, priority int) CompressOption
- type ExcludeFunc
Constants ¶
const ( BrotliBestSpeed = brotli.BestSpeed BrotliBestCompression = brotli.BestCompression BrotliDefaultCompression = brotli.DefaultCompression )
const ( DEFLATE = "deflate" GZIP = "gzip" ZSTD = "zstd" BROTLI = "br" )
const ( GzFlateDefault = flate.DefaultCompression GzFlateNoCompression = flate.NoCompression GzFlateBestSpeed = flate.BestSpeed GzFlateBestCompression = flate.BestCompression GzFlateConstantCompression = flate.ConstantCompression GzFlateHuffmanOnly = flate.HuffmanOnly )
GzFlate* constants are suitable for both Deflate and GZIP
const ( ZstdSpeedFastest = int(zstd.SpeedFastest) ZstdSpeedDefault = int(zstd.SpeedDefault) ZstdSpeedBetterCompression = int(zstd.SpeedBetterCompression) ZstdSpeedBestCompression = int(zstd.SpeedBestCompression) )
Variables ¶
This section is empty.
Functions ¶
func Compress ¶
func Compress(opts ...CompressOption) gin.HandlerFunc
Compress creates the Compress middleware with the provided options
Types ¶
type CompressOption ¶
type CompressOption func(opts *compressOptions)
func WithAlgo ¶
func WithAlgo(algo string, enable bool) CompressOption
WithAlgo specifies whether algo should be enabled for both compression and decompression
func WithCompressLevel ¶
func WithCompressLevel(algo string, level int) CompressOption
WithCompressLevel specifies what level to use for compression. Take care that the specified level is valid for the algorithm you've selected.
func WithDecompressBody ¶
func WithDecompressBody(decompress bool) CompressOption
WithDecompressBody specifies whether to decompress the request body
func WithExcludeFunc ¶
func WithExcludeFunc(f func(c *gin.Context) bool) CompressOption
WithExcludeFunc specifies a function that is called before compression to determine if the response to the current request shouldn't be compressed.
func WithMaxDecodeSteps ¶
func WithMaxDecodeSteps(steps int) CompressOption
WithMaxDecodeSteps specifies how many layers of request body compression to undo if multiple.
func WithMinCompressBytes ¶
func WithMinCompressBytes(numBytes int) CompressOption
WithMinCompressBytes specifies the minimum size a response must be before compressing. Using a value <= 0 will always compress.
func WithPriority ¶
func WithPriority(algo string, priority int) CompressOption
WithPriority specifies which compression algo to use when the client can accept multiple algorithms. The highest priority algorithm that the client will accept wins.
type ExcludeFunc ¶
ExcludeFunc should return true if compression should be skipped for the current request