This is the first time I am writing any golang code and am building a basic web api. What I want to do is whenever a request is received on "/"
path, I want to write out all the paths of mux.Walk()
to my ResponseWriter
. Since the Walk
function takes an anonymous function, how can I make the handler wait until all the paths are calculated and entered into my array which I can send out? If not waiting, is there a more efficient way of doing this?
Since the Walk function takes an anonymous function, how can I make the handler wait until all the paths are calculated and entered into my array which I can send out?
The output of the Walk
function does not change, since you'll eventually end up with a static binary. In other words, you only need to get the ouput of the Walk
function once.
If not waiting, is there a more efficient way of doing this?
Have a look at the sample code provided in the official github repository.
You can build your response for walk
after the routes are first initialised, store this response locally, and return it once you receive a request for the available endpoints.