zstdmw

package
v1.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Zstd

func Zstd(level Level) gin.HandlerFunc

Zstd provides a backward-compatible constructor using default options. It returns a middleware that applies Zstandard response compression when clients advertise support.

func ZstdWith

func ZstdWith(level Level, o Options) gin.HandlerFunc

ZstdWith returns the middleware configured with the fluent Options builder.

Types

type Level

type Level int

Level represents abstract compression levels similar to gzip middleware. They are mapped to klauspost/compress zstd encoder options.

const (
	DefaultCompression Level = iota
	BestSpeed
	BetterCompression // reasonable ratio with good speed
	BestCompression   // maximum compression, slower
)

type Options

type Options interface {
	// WithMinLength sets the minimum content length (in bytes) for compression and returns the updated Options instance.
	WithMinLength(n int) Options

	// WithSkipper sets a custom function to determine whether a request should skip compression and returns the updated Options.
	WithSkipper(f func(*gin.Context) bool) Options

	// WithExcludeExtensions adds specified file extensions to the exclusion list, skipping compression for matching requests.
	WithExcludeExtensions(exts ...string) Options

	// WithExcludePaths adds the specified paths to the exclusion list, skipping compression for requests matching these paths.
	WithExcludePaths(paths ...string) Options
	// contains filtered or unexported methods
}

Options defines a fluent builder interface for configuring the zstd middleware. Use NewOptions() to construct an instance and pass it to ZstdWith.

func NewOptions

func NewOptions() Options

NewOptions creates a new options builder.

type ZstdEncoder

type ZstdEncoder interface {
	Write(p []byte) (int, error)
	Close() error
}

ZstdEncoder is the minimal interface implemented by a Zstandard encoder used by this package. It is deliberately small to allow plugging in fakes/mocks in tests and to decouple from the concrete klauspost/compress implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL