Is it possible to remove or replace routes?
With this pkg you define the named routes and associated handlers. With middleware you'd control flow.
You may want to elaborate on the question.. what are you trying to do?
All of the examples show building the router up and then passing it to http.ListenAndServe.
Ideally I want to be able to keep a handle to the base router and modify it after Serve().
Digging through the tree code it appears there is no way to remove routes or middleware.
Yes, this can be useful
whats the use case / scenario for removing routes at runtime? if you require that, you should probably think to break apart your router into parts and join it together as you need depending on flow
I'm plan to use it on api gateway.
So when some service started new routes must be added, when service stopped, routes must be removed
Interesting. What's the benefit of building an api gateway using a generic router such as this one, where you mount/unmount routes dynamically at runtime?
Say a request comes in, the route was previously unmounted, what happens?
Why not encapsulate the logic of that routed unit into a single microservice with own router and when the microservice "dies" so do the routes?
I'd imagine if you want dynamic un/mounting of routes it should be a concern of the api gateway service _itself_, i.e., something would need to maintain state of routes that are "on/off".
Sorry @pkieltyka, I know this isn't really an _issue_ but I'm genuinely curious.
fwiw, you may want to take a look at the routerSwap approach. I've seen this come up a few times over the years, but could never understand why you'd want this as part of the router pkg.
https://github.com/gorilla/mux/issues/82#issuecomment-121411186
the routerswap approach would work for replacing, but what about removing routes?
@mfridman when the route is removed , you must returns 404 not found. As no service can process request and path not handled. Encapsulation to additional service means that you need to transfer all data to it and it must works as proxy. This is additional spof, or it must be distributed..
this isn't something I'm planning to add to the core, it belongs outside of the router, for example, create a new one and mount/swap outside above the individual router
I have another use case: I am code generating simple crud handlers for all my entities. Sometimes i want to be able to swap some of the generated methods out for another one (so i do not need the removing part).
Currently i have a huge amount of configuration, so some of the routes for some entities are not getting generated so i can pass in some custom logic.