Export the funcs: AcquireCtx and ReleaseCtx, see previous commit for more

This commit is contained in:
Gerasimos Maropoulos 2016-09-18 07:21:35 +03:00
parent 131eddb701
commit 4eee3e5f53

23
iris.go
View File

@ -145,6 +145,8 @@ type (
ListenTLS(string, string, string)
ListenUNIX(string, os.FileMode)
ListenVirtual(...string) *Server
AcquireCtx(*fasthttp.RequestCtx) *Context
ReleaseCtx(*Context)
Go() error
Close() error
UseSessionDB(sessions.Database)
@ -301,16 +303,24 @@ func (s *Framework) initialize() {
}
// Go starts the iris station, listens to all registered servers, and prepare only if Virtual
func Go() error {
return Default.Go()
// AcquireCtx gets an Iris' Context from pool
// see iris.Handler & ReleaseCtx, Go()
func AcquireCtx(reqCtx *fasthttp.RequestCtx) {
Default.AcquireCtx(reqCtx)
}
// ReleaseCtx puts the Iris' Context back to the pool in order to be re-used
// see iris.Handler & AcquireCtx, Go()
func ReleaseCtx(ctx *Context) {
Default.ReleaseCtx(ctx)
}
// AcquireCtx gets an Iris' Context from pool
// see iris.Handler & ReleaseCtx, Go()
func (s *Framework) AcquireCtx(reqCtx *fasthttp.RequestCtx) {
func (s *Framework) AcquireCtx(reqCtx *fasthttp.RequestCtx) *Context {
ctx := s.contextPool.Get().(*Context) // Changed to use the pool's New 09/07/2016, ~ -4k nanoseconds(9 bench tests) per requests (better performance)
ctx.RequestCtx = reqCtx
return ctx
}
// ReleaseCtx puts the Iris' Context back to the pool in order to be re-used
@ -322,6 +332,11 @@ func (s *Framework) ReleaseCtx(ctx *Context) {
s.contextPool.Put(ctx)
}
// Go starts the iris station, listens to all registered servers, and prepare only if Virtual
func Go() error {
return Default.Go()
}
// Go starts the iris station, listens to all registered servers, and prepare only if Virtual
func (s *Framework) Go() error {
s.initialize()