I'm new to go and want to set up some routing, as well as cors
. I've been seeing two styles of doing so, one that initializes a multiplexer with NewServeMux
and then assigns handlers with HandleFunc
, and one that uses HandleFunc
directly on http
. This is what I mean:
mux := http.NewServeMux()
mux.HandleFunc("/api", apiFunc)
mux.HandleFunc("/", indexFunc)
vs
http.HandleFunc("/api", apiFunc)
http.HandleFunc("/", indexFunc)
http.ListenAndServe("127.0.0.1:3001", nil)
Are there any differences with these approaches? If they accomplish similar things, is one more common/pragmatic?