How to get the full host and url in go-restful

In my JSON output I want to output absolute path to other REST resources, but I don't know how I can obtain all the relevant parts to build the Path, such as transport (http/https), host, port, root path.

After playing with this for a while, I ended up trying it both ways. It turns out that at least some of the information can be extracted from Request (note: I presume that if the route were defined with an absolute url then all of this information could be had from Request.URL)

The above prints the following to the browser. I suppose one could use this to construct urls to jsonify, although it's not clear how the base path would be parsed out without some prior knowledge of either the base path or the specific path, or some syntactic convention for distinguishing the two.

Protocol: HTTP/1.1
Host: localhost:8080
Path: /hello

The second thing I tried was to define a URL at package level and use that to build a custom parse function. url.URL maintains a struct representation of a URL; A relative (or absolute) path can be parsed and merged with an existing URL using URL.parse(string). Conveniently, URL can output a string representation of itself via it's String() method.

The custom parse function simply holds on to a copy of the package level URL, and each time it is called with some specific path it pastes the new path on to the end of the URL.Path and returns a new URL that's identical except for the new concatenated path (because that's what URL.parse() does when we hand it a relative path). URL.String() can then be called on the new URL to stringify the URL into the string that we want to marshal.