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

# Packages

No description provided by the author

# 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.