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.
-
Import the package
import "github.com/go-swiss/compress"
-
Add
compress.Middleware
to your router.
import (
"net/http"
"github.com/go-swiss/compress"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", HomeHandler)
http.ListenAndServe(":8080", compress.Middleware(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)
}
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)
}