Skip to content

Commit aa5d8ee

Browse files
authored
refactor: optimize gzip writer pool management and resource handling (#102)
- Remove deferred function that resets and puts the gzip writer back into the pool - Add immediate return of the gzip writer to the pool after resetting it Signed-off-by: appleboy <[email protected]>
1 parent 4fc267c commit aa5d8ee

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

handler.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ func (g *gzipHandler) Handle(c *gin.Context) {
7575
}
7676

7777
gz := g.gzPool.Get().(*gzip.Writer)
78-
defer func() {
79-
gz.Reset(io.Discard)
80-
g.gzPool.Put(gz)
81-
}()
8278
gz.Reset(c.Writer)
8379

8480
c.Header(headerContentEncoding, "gzip")
@@ -98,6 +94,7 @@ func (g *gzipHandler) Handle(c *gin.Context) {
9894
if c.Writer.Size() > -1 {
9995
c.Header("Content-Length", strconv.Itoa(c.Writer.Size()))
10096
}
97+
g.gzPool.Put(gz)
10198
}()
10299
c.Next()
103100
}

0 commit comments

Comments
 (0)