This should work. Both invocations use http.DefaultServeMux
, which is a package-level variable that is the very same object for both imports.
That said, it would be better design if you passed a *http.ServeMux
into Register
so the caller has control over where the handler gets added:
Register(mux *http.ServeMux) {
mux.Handle("/echo", websocket.Handler(Wshandle))
...
}
And in main
:
http.HandleFunc("/aa", aahandler)
bbhandler.Register(http.DefaultServeMux)
...
http.ListenAndServe()