英文:
go-restful extract URL pattern path from request
问题
我正在使用emicklei/go-restful框架处理REST API。我希望能够从请求中访问路由路径。也就是说,当我配置一个虚拟路由时,我希望能够访问到路由的信息,例如:
ws := new(restful.WebService)
ws.Path("/resources/names")
ws.Route(ws.GET("/{name}").To(getName))
restful.DefaultContainer.Add(ws)
我希望能够访问到路由的路径信息,即"/resources/names/{name}"。
通过调用req.Request.URL.Path
可以获取到实际的URL,但这只会返回具体的URL,而不是通用的路由路径。
有什么建议吗?
英文:
I am using a the emicklei/go-restful framework to deal with rest API.
I wish to access the route path from the request. Meaning that when I configure a dummy route like this:
ws := new(restful.WebService)
ws.Path("/resources/names")
ws.Route(ws.GET("/{name}").To(getName))
restful.DefaultContainer.Add(ws)
I wish to access the information that the route was "/resources/names/{name}"
I can access the actual URL which is call by calling:
req.Request.URL.Path
But this will return the specific URL, not the generic one.
Any suggestion?
答案1
得分: 0
经过更多的研究,我终于发现方法req.SelectedRoutePath()将返回预期的值。
英文:
After more research I finally found that the method req.SelectedRoutePath() will return expected value.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论