The 404 isn't being returned by Goji—any 404 from Goji should be logged to console (stdout) by the Logger
middleware. The upstream handler passing requests to the Goji router is bouncing anything that isn't /api/list
.
You can fix this with a more lenient match:
package main
import (
"fmt"
"net/http"
"github.com/zenazn/goji/web"
"github.com/zenazn/goji/web/middleware"
)
func main() {
mux := web.New()
http.Handle("/api/", mux)
mux.Use(middleware.EnvInit)
mux.Use(middleware.Logger)
mux.Get("/api/list/:id", debugHandler)
mux.Get("/api/list", debugHandler)
mux.Post("/api/list", debugHandler)
// If Goji's router 404's, we should call our custom handler, and it
// should also be apparent in the logs.
mux.NotFound(notFoundHandler)
http.ListenAndServe(":8000", nil)
}
func debugHandler(c web.C, w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%v
", r.URL.Path)
}
func notFoundHandler(c web.C, w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("Goji 404: %s", r.URL.Path), 404)
}
Note that I've changed the upstream http.Handle
to http.Handle("/api/", mux)
to provide a more lenient match. The net/http
router is very simple and because /api/list/131313
(e.g. with an id) doesn't match /api/list
it 404's before it even hits the Goji mux instance you created.
Hope that helps.