如何在请求中转义正斜杠以使url路由器将其视为uri参数的一部分?

I have following route mapping using gorilla/mux:

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

when I call curl http://localhost:8080/v1/data/hello%2Fworld I get 404 response code. The problem is that in my microservice I would like to interpret everything that goes after /v1/data/ as param.

Code that's capturing params is following:

uriP := mux.Vars(r)
param := uriP["param"]

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

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"]