compress

package module
v0.0.0-...-c7b5657 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 6 Imported by: 0

README

Compression Middleware

This package provides a middleware for the Go's net/http (or other compatible routers) that compresses the response using brotli or gzip compression algorithms.

It depends only on https://github.com/andybalholm/brotli.

Usage

  1. Import the package

    import "github.com/go-swiss/compress"
    
  2. Add compress.Middleware to your router.

With net/http
import (
    "net/http"

    "github.com/go-swiss/compress"
)

func main() {
    mux := http.NewServeMux()
    mux.HandleFunc("/", HomeHandler)

    http.ListenAndServe(":8080", compress.Middleware(mux))
}
With gorilla/mux
import (
    "net/http"

    "github.com/go-swiss/compress"
    "github.com/gorilla/mux"
)

func main() {
    r := mux.NewRouter()
    r.Use(compress.Middleware)
    r.HandleFunc("/", HomeHandler)

    http.ListenAndServe(":8080", r)
}
With go-chi/chi
import (
    "net/http"

    "github.com/go-chi/chi/v5"
    "github.com/go-swiss/compress"
)

func main() {
    r := chi.NewRouter()
    r.Use(compress.Middleware)
    r.Get("/", HomeHandler)

    http.ListenAndServe(":8080", r)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(h http.Handler) http.Handler

Middleware provides a middleware that compresses the response body using brotli or gzip

Types

This section is empty.

Jump to

Keyboard shortcuts

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