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:
11
context.go
11
context.go
@ -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 ***********/
|
||||
/************************************/
|
||||
|
Reference in New Issue
Block a user