New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: net/http: add Unregister method to ServeMux #50056
Comments
Seems extremely racey. If you need this functionality, why not just register a handler for / and then mux it yourself at runtime? I don't think this fits into the usecase for the standard serve mux, and it's very easy to write your own, so I would be opposed to any performance hit that would come from checking a lock at runtime. |
The internal locking protects against basic races. |
I don't think this is generally useful enough to warrant adding, and I suspect that a need to unregister handlers from a |
The design of ServeMux is intentionally order-independent, so that if you have things registered from init functions, it doesn't matter what order the init functions run. I'm very wary of adding something that would introduce order dependence in this API. There are many other options if you need this functionality, of course, including writing a trivial custom mux. |
This proposal has been added to the active column of the proposals project |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
Currently it is not possible to dynamically register and deregister path handlers with a
ServeMux
object. Once a handler for a path is registered, it cannot be changed or removed.Solutions to work around this (such as wrapping
ServeMux
) can lead to a growing map containing stale handlers.The proposal is to add an
Unregister
method with the following function signature:func (mux *ServeMux) Unregister(pattern string)
The text was updated successfully, but these errors were encountered: