In most of the docs I have seen, gorilla mux is suggested to be used like so...
func main() {
m := mux.Router()
m.HandleFunc("/", FuncNameOrDef)
http.ListenAndServe(":8080", m)
}
which is great, but it leaves me with a problem, because then in order to test, as far as I can see, I need to redeclare mux and routes unless I declare mux and routes outside of a function like this...
var (
m = mux.Router()
_ = m.HandleFunc("/", FuncNameOrDef)
)
and then in my tests do this...
func TestSomeView(t *testing.T) {
ts := httptest.NewServer(m)
....testing blah
}
which solves the problem, but then it makes the package pretty ugly (with all the _ = m.HandleFunc
's) Is there a more idiomatic way to do this?