mirror of https://github.com/gin-gonic/gin.git
Fixes performance regression
This commit is contained in:
parent
21979d6a99
commit
0b043d0886
3
gin.go
3
gin.go
|
@ -158,7 +158,7 @@ func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
|
||||||
panic("there must be at least one handler")
|
panic("there must be at least one handler")
|
||||||
}
|
}
|
||||||
|
|
||||||
root := engine.trees.get("method")
|
root := engine.trees.get(method)
|
||||||
if root == nil {
|
if root == nil {
|
||||||
root = new(node)
|
root = new(node)
|
||||||
engine.trees = append(engine.trees, methodTree{
|
engine.trees = append(engine.trees, methodTree{
|
||||||
|
@ -247,6 +247,7 @@ func (engine *Engine) handleHTTPRequest(context *Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,26 @@ func testRouteNotOK2(method string, t *testing.T) {
|
||||||
assert.Equal(t, w.Code, http.StatusMethodNotAllowed)
|
assert.Equal(t, w.Code, http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRouterMethod(t *testing.T) {
|
||||||
|
router := New()
|
||||||
|
router.PUT("/hey2", func(c *Context) {
|
||||||
|
c.String(200, "sup2")
|
||||||
|
})
|
||||||
|
|
||||||
|
router.PUT("/hey", func(c *Context) {
|
||||||
|
c.String(200, "called")
|
||||||
|
})
|
||||||
|
|
||||||
|
router.PUT("/hey3", func(c *Context) {
|
||||||
|
c.String(200, "sup3")
|
||||||
|
})
|
||||||
|
|
||||||
|
w := performRequest(router, "PUT", "/hey")
|
||||||
|
|
||||||
|
assert.Equal(t, w.Code, 200)
|
||||||
|
assert.Equal(t, w.Body.String(), "called")
|
||||||
|
}
|
||||||
|
|
||||||
func TestRouterGroupRouteOK(t *testing.T) {
|
func TestRouterGroupRouteOK(t *testing.T) {
|
||||||
testRouteOK("GET", t)
|
testRouteOK("GET", t)
|
||||||
testRouteOK("POST", t)
|
testRouteOK("POST", t)
|
||||||
|
|
Loading…
Reference in New Issue