mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 14:52:18 +08:00
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:
parent
7742ff50e0
commit
dd0547fb2d
8
gin.go
8
gin.go
@ -165,7 +165,10 @@ func Default() *Engine {
|
|||||||
|
|
||||||
func (engine *Engine) allocateContext() *Context {
|
func (engine *Engine) allocateContext() *Context {
|
||||||
v := make(Params, 0, engine.maxParams)
|
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.
|
// 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 := engine.pool.Get().(*Context)
|
||||||
c.writermem.reset(w)
|
c.writermem.reset(w)
|
||||||
c.Request = req
|
c.Request = req
|
||||||
c.reset()
|
|
||||||
|
|
||||||
engine.handleHTTPRequest(c)
|
engine.handleHTTPRequest(c)
|
||||||
|
|
||||||
|
// clear request data
|
||||||
|
c.reset()
|
||||||
engine.pool.Put(c)
|
engine.pool.Put(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user