Documentation
¶
Index ¶
Constants ¶
View Source
const (
CompressMinSizeDefault = 1024
)
Variables ¶
View Source
var Default = New(Options{})
Get the default compression middleware. All options are defaulted.
Functions ¶
func DefaultFilter ¶
Default filter function which applies compression to text/* and application/* content types.
func New ¶
func New(options Options) xhttp.Middleware
Create a Middleware that compresses response automatically based on content encoding, type, and length.
Types ¶
type Algorithm ¶
type Algorithm struct {
// Name of an encoding algorithm which must match an Accept-Encoding value
// exactly.
Name string
// Return a WriteCloser that wraps the provided io.Writer with compression.
GetWriter func(io.Writer) (io.WriteCloser, error)
}
Compression algorithm definition.
func BrotliLevel ¶
Brotli compression algorithm with custom compression level.
func Deflate ¶
func Deflate() Algorithm
Deflate compression algorithm with default compression level.
func DeflateLevel ¶
Deflate compression algorithm with custom compression level.
func ZstdLevel ¶
func ZstdLevel(level zstd.EncoderLevel) Algorithm
Zstd compression algorithm with custom compression level.
type Options ¶
type Options struct {
// Filter requests that are eligible for compression. If nil, all text/* and
// application/* types are compressed.
Filter Filter
// Minimum size in bytes to trigger compression. If zero,
// CompressMinSizeDefault is used.
MinSize int
// Supported compression Algorithm slice in order of preference. If empty,
// Brotli, Gzip, and Deflate are supported.
Algorithms []Algorithm
}
Compression middleware options.
Click to show internal directories.
Click to hide internal directories.