Help with Negroni / Gorilla Mux combination
jtkelley opened this issue · 2 comments
Can anyone help getting Yaag to work with Negroni and Gorilla Mux? No matter what I try I seem to get nothing or I get mulitple http write errors probably because because I already have routes.
I have tried this and a few other things ...
`
yaag.Init(&yaag.Config{On: true, DocTitle: "Negroni-gorilla", DocPath: "apidoc.html", BaseUrls: map[string]string{"Production": "", "Staging": ""}})
router := mux.NewRouter()
// ... Add a bunch of routes
router.HandleFunc("/", middleware.HandleFunc(handler)) //this does nothing
n := negroni.Classic()
n.Use(c)
//n.UseHandlerFunc(middleware.HandleFunc(handler)) //this gives an error but makes a doc
n.UseHandler(router)
n.Run(":5000")
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, time.Now().String())
}
`
Update:
I got "n.UseHandlerFunc(middleware.HandleFunc(handler))" to work by removing
"fmt.Fprintf(w, time.Now().String())" from the handler. It looks like once I write a response it finishes.
Not sure if that is really working or not.
I still don't get responses. Just requests.
Another_ question (if the first question can be solved):
All the examples show just returning time. How do you return the actual response?
Maybe this would become more apparent if this was working for me. But it seems like all the handlers just return time. Help my Ignorance. Are the responses generated in the middleware somehow?
I know we could return something else in the handler but I don't see how to return a response.
I'm running into the problem of incorporating YAAG with Negroni as well. Would like to be able to call it as n.Use() like the martini version.
I have added the negroni + gorrilla example. It is tested working, attached the generated html
apidoc.txt
@eirikant you can use n.UseHandler(middleware.Handle(router))
This will work for all routes, with a single line.