Categorygithub.com/lightning-contrib/compress
modulepackage
1.0.0
Repository: https://github.com/lightning-contrib/compress.git
Documentation: pkg.go.dev

# README

Compress

This is a middleware for lightning that provides compression for HTTP responses. It supports four compression algorithms: Brotli, Deflate, Gzip, and Zstd.

Installation

To install the middleware, run the following command:

go get github.com/lightning-contrib/compress

Usage

To use the middleware, import the package and add it to your lightning middleware chain:

package main

import (
	"github.com/go-labx/lightning"
	"github.com/lightning-contrib/compress"
)

func main() {
	app := lightning.NewApp()

	app.Use(compress.Default())

	app.Get("/ping", func(ctx *lightning.Context) {
		ctx.Text(200, "hello world")
	})

	app.Run(":6789")
}

By default, the middleware will use the following compression levels:

  • Brotli: brotli.DefaultCompression
  • Deflate: flate.DefaultCompression
  • Gzip: gzip.DefaultCompression

You can customize the compression levels by passing options to the New function:

app.Use(compress.New(
    compress.WithBrotliCompressionLevel(6),
    compress.WithDeflateCompressionLevel(9),
    compress.WithGzipCompressionLevel(1),
))

Supported Encodings

The middleware supports the following encodings:

  • br (Brotli)
  • deflate (Deflate)
  • gzip (Gzip)
  • zstd (Zstd)

If the client sends a request with an Accept-Encoding header that includes one of these encodings, the middleware will compress the response using the corresponding algorithm.

API Documentation

For detailed API documentation and usage examples, please refer to the documentation.

Contributing

If you'd like to contribute to lightning, please see CONTRIBUTING.md for guidelines.

License

This middleware is licensed under the MIT License. See LICENSE for more information.

# Packages

No description provided by the author

# Functions

Default returns a lightning middleware with default options.
New returns a lightning middleware with the given options.
WithBrotliCompressionLevel sets the compression level for Brotli compression algorithm.
WithDeflateCompressionLevel sets the compression level for Deflate compression algorithm.
WithGzipCompressionLevel sets the compression level for Gzip compression algorithm.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

Compressor is an interface that defines the Compress method.

# Type aliases

Options is a function that takes a pointer to a config struct.