Hold matched route full path in the Context (#1826)

* Return nodeValue from getValue method

* Hold route full path in the Context

* Add small example
This commit is contained in:
Roman Zaynetdinov
2019-05-26 03:20:21 +03:00
committed by 田欧
parent 78a8b5c9d5
commit 35e33d3638
6 changed files with 117 additions and 46 deletions

View File

@ -48,6 +48,7 @@ type Context struct {
Params Params
handlers HandlersChain
index int8
fullPath string
engine *Engine
@ -70,6 +71,7 @@ func (c *Context) reset() {
c.Params = c.Params[0:0]
c.handlers = nil
c.index = -1
c.fullPath = ""
c.Keys = nil
c.Errors = c.Errors[0:0]
c.Accepted = nil
@ -111,6 +113,15 @@ func (c *Context) Handler() HandlerFunc {
return c.handlers.Last()
}
// FullPath returns a matched route full path. For not found routes
// returns an empty string.
// router.GET("/user/:id", func(c *gin.Context) {
// c.FullPath() == "/user/:id" // true
// })
func (c *Context) FullPath() string {
return c.fullPath
}
/************************************/
/*********** FLOW CONTROL ***********/
/************************************/