1
1
# GZIP gin's middleware
2
2
3
- [ ![ Build Status ] ( https://travis-ci.org /gin-contrib/gzip. svg )] ( https://travis-ci.org /gin-contrib/gzip )
3
+ [ ![ Run Tests ] ( https://github.com /gin-contrib/gzip/actions/workflows/go.yml/badge. svg )] ( https://github.com /gin-contrib/gzip/actions/workflows/go.yml )
4
4
[ ![ codecov] ( https://codecov.io/gh/gin-contrib/gzip/branch/master/graph/badge.svg )] ( https://codecov.io/gh/gin-contrib/gzip )
5
5
[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/gin-contrib/gzip )] ( https://goreportcard.com/report/github.com/gin-contrib/gzip )
6
6
[ ![ GoDoc] ( https://godoc.org/github.com/gin-contrib/gzip?status.svg )] ( https://godoc.org/github.com/gin-contrib/gzip )
@@ -28,23 +28,25 @@ Canonical example:
28
28
package main
29
29
30
30
import (
31
- " fmt"
32
- " net/http"
33
- " time"
31
+ " fmt"
32
+ " net/http"
33
+ " time"
34
34
35
- " github.com/gin-contrib/gzip"
36
- " github.com/gin-gonic/gin"
35
+ " github.com/gin-contrib/gzip"
36
+ " github.com/gin-gonic/gin"
37
37
)
38
38
39
39
func main () {
40
- r := gin.Default ()
41
- r.Use (gzip.Gzip (gzip.DefaultCompression ))
42
- r.GET (" /ping" , func (c *gin.Context ) {
43
- c.String (http.StatusOK , " pong " +fmt.Sprint (time.Now ().Unix ()))
44
- })
45
-
46
- // Listen and Server in 0.0.0.0:8080
47
- r.Run (" :8080" )
40
+ r := gin.Default ()
41
+ r.Use (gzip.Gzip (gzip.DefaultCompression ))
42
+ r.GET (" /ping" , func (c *gin.Context ) {
43
+ c.String (http.StatusOK , " pong " +fmt.Sprint (time.Now ().Unix ()))
44
+ })
45
+
46
+ // Listen and Server in 0.0.0.0:8080
47
+ if err := r.Run (" :8080" ); err != nil {
48
+ log.Fatal (err)
49
+ }
48
50
}
49
51
```
50
52
@@ -54,23 +56,25 @@ Customized Excluded Extensions
54
56
package main
55
57
56
58
import (
57
- " fmt"
58
- " net/http"
59
- " time"
59
+ " fmt"
60
+ " net/http"
61
+ " time"
60
62
61
- " github.com/gin-contrib/gzip"
62
- " github.com/gin-gonic/gin"
63
+ " github.com/gin-contrib/gzip"
64
+ " github.com/gin-gonic/gin"
63
65
)
64
66
65
67
func main () {
66
- r := gin.Default ()
67
- r.Use (gzip.Gzip (gzip.DefaultCompression , gzip.WithExcludedExtensions ([]string {" .pdf" , " .mp4" })))
68
- r.GET (" /ping" , func (c *gin.Context ) {
69
- c.String (http.StatusOK , " pong " +fmt.Sprint (time.Now ().Unix ()))
70
- })
71
-
72
- // Listen and Server in 0.0.0.0:8080
73
- r.Run (" :8080" )
68
+ r := gin.Default ()
69
+ r.Use (gzip.Gzip (gzip.DefaultCompression , gzip.WithExcludedExtensions ([]string {" .pdf" , " .mp4" })))
70
+ r.GET (" /ping" , func (c *gin.Context ) {
71
+ c.String (http.StatusOK , " pong " +fmt.Sprint (time.Now ().Unix ()))
72
+ })
73
+
74
+ // Listen and Server in 0.0.0.0:8080
75
+ if err := r.Run (" :8080" ); err != nil {
76
+ log.Fatal (err)
77
+ }
74
78
}
75
79
```
76
80
@@ -80,49 +84,52 @@ Customized Excluded Paths
80
84
package main
81
85
82
86
import (
83
- " fmt"
84
- " net/http"
85
- " time"
87
+ " fmt"
88
+ " net/http"
89
+ " time"
86
90
87
- " github.com/gin-contrib/gzip"
88
- " github.com/gin-gonic/gin"
91
+ " github.com/gin-contrib/gzip"
92
+ " github.com/gin-gonic/gin"
89
93
)
90
94
91
95
func main () {
92
- r := gin.Default ()
93
- r.Use (gzip.Gzip (gzip.DefaultCompression , gzip.WithExcludedPaths ([]string {" /api/" })))
94
- r.GET (" /ping" , func (c *gin.Context ) {
95
- c.String (http.StatusOK , " pong " +fmt.Sprint (time.Now ().Unix ()))
96
- })
97
-
98
- // Listen and Server in 0.0.0.0:8080
99
- r.Run (" :8080" )
96
+ r := gin.Default ()
97
+ r.Use (gzip.Gzip (gzip.DefaultCompression , gzip.WithExcludedPaths ([]string {" /api/" })))
98
+ r.GET (" /ping" , func (c *gin.Context ) {
99
+ c.String (http.StatusOK , " pong " +fmt.Sprint (time.Now ().Unix ()))
100
+ })
101
+
102
+ // Listen and Server in 0.0.0.0:8080
103
+ if err := r.Run (" :8080" ); err != nil {
104
+ log.Fatal (err)
105
+ }
100
106
}
101
107
```
102
108
103
-
104
109
Customized Excluded Paths
105
110
106
111
``` go
107
112
package main
108
113
109
114
import (
110
- " fmt"
111
- " net/http"
112
- " time"
115
+ " fmt"
116
+ " net/http"
117
+ " time"
113
118
114
- " github.com/gin-contrib/gzip"
115
- " github.com/gin-gonic/gin"
119
+ " github.com/gin-contrib/gzip"
120
+ " github.com/gin-gonic/gin"
116
121
)
117
122
118
123
func main () {
119
- r := gin.Default ()
120
- r.Use (gzip.Gzip (gzip.DefaultCompression , gzip.WithExcludedPathsRegexs ([]string {" .*" })))
121
- r.GET (" /ping" , func (c *gin.Context ) {
122
- c.String (http.StatusOK , " pong " +fmt.Sprint (time.Now ().Unix ()))
123
- })
124
-
125
- // Listen and Server in 0.0.0.0:8080
126
- r.Run (" :8080" )
124
+ r := gin.Default ()
125
+ r.Use (gzip.Gzip (gzip.DefaultCompression , gzip.WithExcludedPathsRegexs ([]string {" .*" })))
126
+ r.GET (" /ping" , func (c *gin.Context ) {
127
+ c.String (http.StatusOK , " pong " +fmt.Sprint (time.Now ().Unix ()))
128
+ })
129
+
130
+ // Listen and Server in 0.0.0.0:8080
131
+ if err := r.Run (" :8080" ); err != nil {
132
+ log.Fatal (err)
133
+ }
127
134
}
128
135
```
0 commit comments