thinkerou 5602d8b438 Merge pull request #22 from mkfsn/master | 5 rokov pred | |
---|---|---|
example | 7 rokov pred | |
.travis.yml | 5 rokov pred | |
LICENSE | 7 rokov pred | |
README.md | 5 rokov pred | |
go.mod | 5 rokov pred | |
go.sum | 5 rokov pred | |
gzip.go | 5 rokov pred | |
gzip_test.go | 5 rokov pred | |
handler.go | 5 rokov pred | |
options.go | 5 rokov pred |
Gin middleware to enable GZIP
support.
Download and install it:
$ go get github.com/gin-contrib/gzip
Import it in your code:
import "github.com/gin-contrib/gzip"
package main
import (
"fmt"
"time"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.Use(gzip.Gzip(gzip.DefaultCompression))
r.GET("/ping", func(c *gin.Context) {
c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
})
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
}
package main
import (
"fmt"
"time"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedExtensions([]string{".pdf", ".mp4"})))
r.GET("/ping", func(c *gin.Context) {
c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
})
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
}
package main
import (
"fmt"
"time"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedPaths([]string{"/api/"})))
r.GET("/ping", func(c *gin.Context) {
c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
})
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
}