package srv import ( "net/http" ) var rtr *http.ServeMux /* Our Special HandleFunc */ func Route(pattern string, handler func(req *Req, res Res)) { realHandler := func(w http.ResponseWriter, r *http.Request) { var req Req var res Res req.Construct(r) res.Construct(w, r) // run middleware on each request for _, fun := range middleware { cont := fun(&req, res) if !cont { return } } handler(&req, res) } rtr.HandleFunc(pattern, realHandler) } func InitRouter() { rtr = http.NewServeMux() // Public Files fs := http.FileServer(http.Dir("app/pub")) rtr.Handle("GET /app/pub/", http.StripPrefix("/app/pub/", fs)) }