Skip to content

Commit 51dd498

Browse files
committed
chore: fix lint
Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 007a8f4 commit 51dd498

File tree

4 files changed

+67
-61
lines changed

4 files changed

+67
-61
lines changed

README.md

+61-54
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GZIP gin's middleware
22

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)
44
[![codecov](https://codecov.io/gh/gin-contrib/gzip/branch/master/graph/badge.svg)](https://codecov.io/gh/gin-contrib/gzip)
55
[![Go Report Card](https://goreportcard.com/badge/github.com/gin-contrib/gzip)](https://goreportcard.com/report/github.com/gin-contrib/gzip)
66
[![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:
2828
package main
2929

3030
import (
31-
"fmt"
32-
"net/http"
33-
"time"
31+
"fmt"
32+
"net/http"
33+
"time"
3434

35-
"github.com/gin-contrib/gzip"
36-
"github.com/gin-gonic/gin"
35+
"github.com/gin-contrib/gzip"
36+
"github.com/gin-gonic/gin"
3737
)
3838

3939
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+
}
4850
}
4951
```
5052

@@ -54,23 +56,25 @@ Customized Excluded Extensions
5456
package main
5557

5658
import (
57-
"fmt"
58-
"net/http"
59-
"time"
59+
"fmt"
60+
"net/http"
61+
"time"
6062

61-
"github.com/gin-contrib/gzip"
62-
"github.com/gin-gonic/gin"
63+
"github.com/gin-contrib/gzip"
64+
"github.com/gin-gonic/gin"
6365
)
6466

6567
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+
}
7478
}
7579
```
7680

@@ -80,49 +84,52 @@ Customized Excluded Paths
8084
package main
8185

8286
import (
83-
"fmt"
84-
"net/http"
85-
"time"
87+
"fmt"
88+
"net/http"
89+
"time"
8690

87-
"github.com/gin-contrib/gzip"
88-
"github.com/gin-gonic/gin"
91+
"github.com/gin-contrib/gzip"
92+
"github.com/gin-gonic/gin"
8993
)
9094

9195
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+
}
100106
}
101107
```
102108

103-
104109
Customized Excluded Paths
105110

106111
```go
107112
package main
108113

109114
import (
110-
"fmt"
111-
"net/http"
112-
"time"
115+
"fmt"
116+
"net/http"
117+
"time"
113118

114-
"github.com/gin-contrib/gzip"
115-
"github.com/gin-gonic/gin"
119+
"github.com/gin-contrib/gzip"
120+
"github.com/gin-gonic/gin"
116121
)
117122

118123
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+
}
127134
}
128135
```

example/example.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"log"
56
"net/http"
67
"time"
78

@@ -17,5 +18,7 @@ func main() {
1718
})
1819

1920
// Listen and Server in 0.0.0.0:8080
20-
r.Run(":8080")
21+
if err := r.Run(":8080"); err != nil {
22+
log.Fatal(err)
23+
}
2124
}

gzip_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ func newCloseNotifyingRecorder() *closeNotifyingRecorder {
4343
}
4444
}
4545

46-
func (c *closeNotifyingRecorder) close() {
47-
c.closed <- true
48-
}
49-
5046
func (c *closeNotifyingRecorder) CloseNotify() <-chan bool {
5147
return c.closed
5248
}

options.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (e ExcludedPaths) Contains(requestURI string) bool {
8585
type ExcludedPathesRegexs []*regexp.Regexp
8686

8787
func NewExcludedPathesRegexs(regexs []string) ExcludedPathesRegexs {
88-
result := make([]*regexp.Regexp, len(regexs), len(regexs))
88+
result := make([]*regexp.Regexp, len(regexs))
8989
for i, reg := range regexs {
9090
result[i] = regexp.MustCompile(reg)
9191
}
@@ -107,7 +107,7 @@ func DefaultDecompressHandle(c *gin.Context) {
107107
}
108108
r, err := gzip.NewReader(c.Request.Body)
109109
if err != nil {
110-
c.AbortWithError(http.StatusBadRequest, err)
110+
_ = c.AbortWithError(http.StatusBadRequest, err)
111111
return
112112
}
113113
c.Request.Header.Del("Content-Encoding")

0 commit comments

Comments
 (0)