No Description

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

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