Skip to content

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.

License

Notifications You must be signed in to change notification settings

go-swiss/compress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
}

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages