Cosmetic changes
This commit is contained in:
26
gin.go
26
gin.go
@ -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
|
||||
|
Reference in New Issue
Block a user