gzip
The gzip middleware provides Gzip compression to responses for Flame instances.
You can read source code of this middleware on GitHub and API documentation on pkg.go.dev.
Installation
go get github.com/flamego/gzip
Usage examples
You should register the gzip.Gzip
before all other middleware or handlers that would write response to clients, and it works out-of-the-box with the default settings:
package main
import (
"github.com/flamego/flamego"
"github.com/flamego/gzip"
)
func main() {
f := flamego.Classic()
f.Use(gzip.Gzip())
f.Get("/", func() string {
return "Hello, Gzip!"
})
f.Run()
}
The gzip.Options
can be used to further customize the behavior of the middleware:
package main
import (
"github.com/flamego/flamego"
"github.com/flamego/gzip"
)
func main() {
f := flamego.Classic()
f.Use(gzip.Gzip(
gzip.Options{
CompressionLevel: 9, // Best compression
},
))
f.Get("/", func() string {
return "Hello, Gzip!"
})
f.Run()
}