Cosmetic changes

This commit is contained in:
Manu Mtz-Almeida
2015-05-18 20:50:46 +02:00
parent 21b5154fd7
commit 9ecb76ef6e
4 changed files with 30 additions and 44 deletions

26
gin.go
View File

@ -175,17 +175,24 @@ func (engine *Engine) RunTLS(addr string, cert string, key string) (err error) {
// ServeHTTP makes the router implement the http.Handler interface.
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
context := engine.pool.Get().(*Context)
context.writermem.reset(w)
context.Request = req
context.reset()
engine.serveHTTPRequest(context)
engine.pool.Put(context)
c := engine.getcontext(w, req)
engine.handleHTTPRequest(c)
engine.putcontext(c)
}
func (engine *Engine) serveHTTPRequest(context *Context) {
func (engine *Engine) getcontext(w http.ResponseWriter, req *http.Request) *Context {
c := engine.pool.Get().(*Context)
c.writermem.reset(w)
c.Request = req
c.reset()
return c
}
func (engine *Engine) putcontext(c *Context) {
engine.pool.Put(c)
}
func (engine *Engine) handleHTTPRequest(context *Context) {
httpMethod := context.Request.Method
path := context.Request.URL.Path
@ -193,7 +200,6 @@ func (engine *Engine) serveHTTPRequest(context *Context) {
if root := engine.trees[httpMethod]; root != nil {
// Find route in tree
handlers, params, tsr := root.getValue(path, context.Params)
// Dispatch if we found any handlers
if handlers != nil {
context.handlers = handlers
context.Params = params