Documentation deprecation of `http.HandleFunc` and `http.Handle`

450 views
Skip to first unread message

matteo....@me.com

unread,
Mar 27, 2016, 3:55:45 PM3/27/16
to golang-dev
This is a follow[0] up to this stackoverflow question. I suggest that `http.HandleFunc` and `http.Handle` get some kind of warning in the docs in favor of `http.ServeMux`. 

Currently, there are two ways to register a listener. The first one is to call `http.HandleFunc` and `http.ServeMux`, which saves you to create a new Mux but uses a global Mux internally. While this may seem convenient, it is a bit confusing for beginners (ambiguity is something every language should try to avoid) and it uses global state, which is strongly discouraged throughout the docs. Furthermore, using DefaultServeMux also runs the risk of exposing profiling endpoints when using net/http/pprof, since those are attached to the DefaultServeMux (thanks elithrar [1][2]). 

Because of those three reasons, I think it is appropriate to add a warning in the Godocs about the shortcomings of those two functions. I'd suggest the docs are changed to "Deprecated, use a ServeMux instead" and the official tutorial[3] is also changed to only use a Mux (this would add 2 more lines, which is acceptable, IMO).

I'd like to know what you think about this issue. 

- Matt3o12 (Matteo Kloiber)

Brad Fitzpatrick

unread,
Mar 27, 2016, 4:24:38 PM3/27/16
to matteo....@me.com, golang-dev
We're not going to prescribe every aspect of how people build their own programs. There might be N ways to do something, each with their own trade-offs, but that's a good thing. We don't need to deprecate all but one of them.


--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages