问题
I'm building a URL shortener API and I'm trying to pass a URL into a function using GorillaMux. The route handler is like so:
router.HandleFunc("/new/{url}", createURL)
The only thing is, if I pass in: https://www.google.com (as in localhost:8080/new/https://www.google.com) then it responds with 404 page not found
and the URL is changed to https:/www.google.com.
I've tried adding a regexp pattern in with the {url} bit like so: {url:[a-zA-Z0-9/]+} but that didn't seem to work and seems a bit overkill since I'm checking the url is correct elsewhere.
回答1:
You need to encode it so that the slash in the parameter was not confused as a part of the url:
localhost:8080/new/https%3A%2F%2Fwww.google.com
来源:https://stackoverflow.com/questions/43626030/why-is-gorillamux-not-allowing-me-to-pass-in-a-url-as-a-parameter