You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
958 B
44 lines
958 B
/* |
|
------------------------------------------------------------------------------------------------------------------------ |
|
####### kong ####### Copyright (c) 2021-2022 losyme ################################################ MIT License ####### |
|
------------------------------------------------------------------------------------------------------------------------ |
|
*/ |
|
|
|
package context |
|
|
|
import ( |
|
"net/http" |
|
"sync" |
|
) |
|
|
|
type Pool struct { |
|
sp *sync.Pool |
|
} |
|
|
|
func NewPool() *Pool { |
|
return &Pool{ |
|
sp: &sync.Pool{ |
|
New: func() interface{} { |
|
return new(Context) |
|
}, |
|
}, |
|
} |
|
} |
|
|
|
func (p *Pool) Get(rw http.ResponseWriter, req *http.Request, rrType RendererType) *Context { |
|
c := p.sp.Get().(*Context) |
|
|
|
c.Request = req |
|
c.Response = rw |
|
c.rrType = rrType |
|
|
|
return c |
|
} |
|
|
|
func (p *Pool) Put(c *Context) { |
|
p.sp.Put(c.reset()) |
|
} |
|
|
|
/* |
|
######################################################################################################## @(°_°)@ ####### |
|
*/
|
|
|