Gzip middleware for Martini.
import (
"github.com/go-martini/martini"
"github.com/martini-contrib/gzip"
)
func main() {
m := martini.Classic()
// gzip every request
m.Use(gzip.All())
m.Run()
}
Make sure to include the Gzip middleware above other middleware that alter the response body (like the render middleware).
You can set compression level using gzip.Options:
import (
"github.com/go-martini/martini"
"github.com/martini-contrib/gzip"
)
func main() {
m := martini.Classic()
// gzip every request with maximum compression level
m.Use(gzip.All(gzip.Options{
CompressionLevel: gzip.BestCompression,
}))
m.Run()
}
The compression level can be DefaultCompression or any integer value between BestSpeed and BestCompression inclusive.