make it clear that the context will be reset after the request ends, otherwise, the timing of the pointer context reset is uncontrollable without constraints

This commit is contained in:
fj.jin 2020-11-17 00:19:04 +08:00
parent 7742ff50e0
commit dd0547fb2d

8
gin.go
View File

@ -165,7 +165,10 @@ func Default() *Engine {
func (engine *Engine) allocateContext() *Context {
v := make(Params, 0, engine.maxParams)
return &Context{engine: engine, params: &v}
c := &Context{engine: engine, params: &v}
// init ctx struct
c.reset()
return c
}
// Delims sets template left and right delims and returns a Engine instance.
@ -371,10 +374,11 @@ func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
c := engine.pool.Get().(*Context)
c.writermem.reset(w)
c.Request = req
c.reset()
engine.handleHTTPRequest(c)
// clear request data
c.reset()
engine.pool.Put(c)
}