Static-Gzipped middleware for gin
Automatically serves pre-gzipped files with gzipped.FileServer
Like gzip_static from nginx, but for gin / go.
This is incompatible with gzip middleware because it will double-compress already gzipped files. Can be used with groups: gin-gonic/gin#1125
Download and install it:
$ go get github.com/glebtv/static_gzipped
Import it in your code:
import "github.com/glebtv/static_gzipped"
See the example
package main
import (
"github.com/glebtv/static_gzipped"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
// if Allow DirectoryIndex
//r.Use(static_gzipped.Serve("/", static_gzipped.LocalFile("/tmp", true)))
// set prefix
//r.Use(static_gzipped.Serve("/static", static_gzipped.LocalFile("/tmp", true)))
r.Use(static_gzipped.Serve("/", static_gzipped.LocalFile("/tmp", false)))
r.GET("/ping", func(c *gin.Context) {
c.String(200, "test")
})
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
}