Reputation: 93
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.
Upvotes: 0
Views: 560
Reputation: 254886
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
Upvotes: 3