mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 05:22:24 -05:00 
			
		
		
		
	Bumps [github.com/gin-contrib/gzip](https://github.com/gin-contrib/gzip) from 1.1.0 to 1.2.2. - [Release notes](https://github.com/gin-contrib/gzip/releases) - [Changelog](https://github.com/gin-contrib/gzip/blob/master/.goreleaser.yaml) - [Commits](https://github.com/gin-contrib/gzip/compare/v1.1.0...v1.2.2) --- updated-dependencies: - dependency-name: github.com/gin-contrib/gzip dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
		
			
				
	
	
		
			169 lines
		
	
	
	
		
			3.3 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			169 lines
		
	
	
	
		
			3.3 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| # GZIP gin's middleware
 | |
| 
 | |
| [](https://github.com/gin-contrib/gzip/actions/workflows/go.yml)
 | |
| [](https://codecov.io/gh/gin-contrib/gzip)
 | |
| [](https://goreportcard.com/report/github.com/gin-contrib/gzip)
 | |
| [](https://godoc.org/github.com/gin-contrib/gzip)
 | |
| 
 | |
| Gin middleware to enable `GZIP` support.
 | |
| 
 | |
| ## Usage
 | |
| 
 | |
| Download and install it:
 | |
| 
 | |
| ```sh
 | |
| go get github.com/gin-contrib/gzip
 | |
| ```
 | |
| 
 | |
| Import it in your code:
 | |
| 
 | |
| ```go
 | |
| import "github.com/gin-contrib/gzip"
 | |
| ```
 | |
| 
 | |
| Canonical example:
 | |
| 
 | |
| ```go
 | |
| package main
 | |
| 
 | |
| import (
 | |
|   "fmt"
 | |
|   "net/http"
 | |
|   "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(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
 | |
|   })
 | |
| 
 | |
|   // Listen and Server in 0.0.0.0:8080
 | |
|   if err := r.Run(":8080"); err != nil {
 | |
|     log.Fatal(err)
 | |
|   }
 | |
| }
 | |
| ```
 | |
| 
 | |
| ### Customized Excluded Extensions
 | |
| 
 | |
| ```go
 | |
| package main
 | |
| 
 | |
| import (
 | |
|   "fmt"
 | |
|   "net/http"
 | |
|   "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(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
 | |
|   })
 | |
| 
 | |
|   // Listen and Server in 0.0.0.0:8080
 | |
|   if err := r.Run(":8080"); err != nil {
 | |
|     log.Fatal(err)
 | |
|   }
 | |
| }
 | |
| ```
 | |
| 
 | |
| ### Customized Excluded Paths
 | |
| 
 | |
| ```go
 | |
| package main
 | |
| 
 | |
| import (
 | |
|   "fmt"
 | |
|   "net/http"
 | |
|   "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(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
 | |
|   })
 | |
| 
 | |
|   // Listen and Server in 0.0.0.0:8080
 | |
|   if err := r.Run(":8080"); err != nil {
 | |
|     log.Fatal(err)
 | |
|   }
 | |
| }
 | |
| ```
 | |
| 
 | |
| ### Customized Excluded Paths with Regex
 | |
| 
 | |
| ```go
 | |
| package main
 | |
| 
 | |
| import (
 | |
|   "fmt"
 | |
|   "net/http"
 | |
|   "time"
 | |
| 
 | |
|   "github.com/gin-contrib/gzip"
 | |
|   "github.com/gin-gonic/gin"
 | |
| )
 | |
| 
 | |
| func main() {
 | |
|   r := gin.Default()
 | |
|   r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedPathsRegexs([]string{".*"})))
 | |
|   r.GET("/ping", func(c *gin.Context) {
 | |
|     c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
 | |
|   })
 | |
| 
 | |
|   // Listen and Server in 0.0.0.0:8080
 | |
|   if err := r.Run(":8080"); err != nil {
 | |
|     log.Fatal(err)
 | |
|   }
 | |
| }
 | |
| ```
 | |
| 
 | |
| ### Server Push
 | |
| 
 | |
| ```go
 | |
| package main
 | |
| 
 | |
| import (
 | |
|   "fmt"
 | |
|   "log"
 | |
|   "net/http"
 | |
|   "time"
 | |
| 
 | |
|   "github.com/gin-contrib/gzip"
 | |
|   "github.com/gin-gonic/gin"
 | |
| )
 | |
| 
 | |
| func main() {
 | |
|   r := gin.Default()
 | |
|   r.Use(gzip.Gzip(gzip.DefaultCompression))
 | |
|   r.GET("/stream", func(c *gin.Context) {
 | |
|     c.Header("Content-Type", "text/event-stream")
 | |
|     c.Header("Connection", "keep-alive")
 | |
|     for i := 0; i < 10; i++ {
 | |
|       fmt.Fprintf(c.Writer, "id: %d\ndata: tick %d\n\n", i, time.Now().Unix())
 | |
|       c.Writer.Flush()
 | |
|       time.Sleep(1 * time.Second)
 | |
|     }
 | |
|   })
 | |
| 
 | |
|   // Listen and Server in 0.0.0.0:8080
 | |
|   if err := r.Run(":8080"); err != nil {
 | |
|     log.Fatal(err)
 | |
|   }
 | |
| }
 | |
| ```
 |