Standard http.ServeMux and how to get all registered path

Can someone help to get all registered path ? e.g./
mux.Handler("/some/path", callSomeFunc())

any advice?

ServeMux registers your handlers to unexported fields, so you can not retrieve them directly. There is no method function for this behavior either. I’m not sure what your use case for this would be, but you could hack something together to test a list of possible paths against the ServeMux.Handler() functions. This would be completely unreliable unless you know what you are looking for, so as path discovery wouldn’t be a real solution.

I am curious if you are attempting to implement a service architecture and trying to get service discovery behavior from your server. If so this is the wrong path for it.

1 Like

Hi! Thanks for answer.
" I’m not sure what your use case for this would be" - just render “system page” where I can see all available routes for my app.

“ServeMux registers your handlers to unexported fields” - Did you means private attr?

I meant what I said lol but they are the same idea in essence. Only your description is more OOP class based, and mine is Go terminology.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.