Bez popisu

thinkerou 5602d8b438 Merge pull request #22 from mkfsn/master před 5 roky
example 6743ec8467 revert to github.com před 7 roky
.travis.yml b07653c4b4 remove go1.6/1.7 from travis před 5 roky
LICENSE 79783a9272 add MIT license (#10) před 7 roky
README.md b3ea4babeb feat: support customized excluded paths před 5 roky
go.mod c1815dcdad update gin 1.4.0 před 5 roky
go.sum c1815dcdad update gin 1.4.0 před 5 roky
gzip.go a5a15a8290 feat: support customized excluded extensions před 5 roky
gzip_test.go b3ea4babeb feat: support customized excluded paths před 5 roky
handler.go b3ea4babeb feat: support customized excluded paths před 5 roky
options.go b3ea4babeb feat: support customized excluded paths před 5 roky

README.md

GZIP gin's middleware

Build Status codecov Go Report Card GoDoc

Gin middleware to enable GZIP support.

Usage

Start using it

Download and install it:

$ go get github.com/gin-contrib/gzip

Import it in your code:

import "github.com/gin-contrib/gzip"

Canonical example:

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")
}

Customized Excluded Extensions

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")
}

Customized Excluded Paths

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")
}