How to escape forward slash in request to make url-routers count it as part of uri parameter?

不羁岁月 提交于 2019-12-02 04:29:41

You should add regexp, bc default regexp is matching until / or ? symbols.

router.Handle("/v1/data/{param:.*}", handler)

For your question:

Is it possible to achieve this using gorilla/mux or any other router?

Yes it is possible using gorilla/mux. There is nothing wrong in the code you have posted.

The error is page not found which means the url that you are passing is not registered with the mux router.

Pass http://localhost:8080/v1/data/hello world on browser. route will capture any parameter after the defined url. Also print the captured url path inside handler request struct to see what is the requested url as:

fmt.Println(r.URL.Path)
uriP := mux.Vars(r)
param := uriP["param"]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!