Skip to content
fox-toolkitPublic

About

Compression middleware for Fox

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Go Reference tests codecov GitHub release (latest SemVer) GitHub go.mod Go version

Compress

Compress is a middleware for Fox that compresses responses with zstd, brotli or gzip, depending on the client Accept-Encoding.

Disclaimer

The current API is not yet stabilized. Breaking changes may occur before v1.0.0 and will be noted on the release note.

Getting started

Installation

go get -u github.com/fox-toolkit/compress

Feature

  • zstd, brotli and gzip, or your own encoder.
  • Compress only bodies above a minimum size.
  • Allowlist or denylist of content types.
  • Choose the encoder order when the client has no preference.
  • Works with streaming responses, like server-sent events or a reverse proxy.

Usage

package main

import (
	"errors"
	"log"
	"net/http"
	"os"

	"github.com/fox-toolkit/compress"
	"github.com/fox-toolkit/fox"
)

func main() {
	mw, err := compress.Middleware(compress.WithMinSize(512))
	if err != nil {
		log.Fatalln(err)
	}

	f := fox.MustRouter(fox.WithMiddleware(mw))

	f.MustAdd(fox.MethodGet, "/*{filepath}", fox.WrapH(http.FileServerFS(os.DirFS("public"))))

	if err := http.ListenAndServe(":8080", f); err != nil && !errors.Is(err, http.ErrServerClosed) {
		log.Fatalln(err)
	}
}

About

Compression middleware for Fox

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages