SkillAgentSearch skills...

Compress

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.

Install / Use

/learn @go-swiss/Compress
About this skill

Quality Score

0/100

Supported Platforms

Universal

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

Related Skills

View on GitHub
GitHub Stars9
CategoryDevelopment
Updated7mo ago
Forks0

Languages

Go

Security Score

82/100

Audited on Sep 2, 2025

No findings