brmw

package
v1.11.13 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Brotli

func Brotli(level Level) gin.HandlerFunc

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

func BrotliWith

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

BrotliWith returns the middleware configured with the fluent Options builder.

Types

type BrotliEncoder

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

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

type Level

type Level int

Level represents abstract compression levels similar to gzip/zstd middleware. They are mapped to brotli quality settings.

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 brotli middleware. Use NewOptions() to construct an instance and pass it to BrotliWith.

func NewOptions

func NewOptions() Options

NewOptions creates a new options builder.

Jump to

Keyboard shortcuts

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