package main import ( "net/http" "github.com/julienschmidt/httprouter" "github.com/justinas/alice" ) // routes ... func (app *application) routes() http.Handler { router := httprouter.New() router.NotFound = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { app.notFound(w) }) router.MethodNotAllowed = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { app.clientError(w, http.StatusMethodNotAllowed) }) // setup server for static files fileServer := http.FileServer(http.Dir("./ui/static")) router.Handler(http.MethodGet, "/static/*filepath", http.StripPrefix("/static", fileServer)) router.HandlerFunc(http.MethodGet, "/", app.home) router.HandlerFunc(http.MethodGet, "/snippet/view/:id", app.snippetView) router.HandlerFunc(http.MethodGet, "/snippet/create", app.snippetCreate) router.HandlerFunc(http.MethodPost, "/snippet/create", app.snippetCreatePost) standard := alice.New(app.recoverPanic, app.logRequest, secureHeaders) return standard.Then(router) }