Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexedwards/41f7e747ee10287bb881fab9e36ed07c to your computer and use it in GitHub Desktop.
Save alexedwards/41f7e747ee10287bb881fab9e36ed07c to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
"github.com/bmizerany/pat"
"github.com/justinas/alice"
)
func (app *application) routes() http.Handler {
standardMiddleware := alice.New(app.recoverPanic, app.logRequest, secureHeaders)
// Important line!
dynamicMiddleware := alice.New(app.session.Enable)
mux := pat.New()
// Important lines: use the dynamicMiddleware chain!
mux.Get("/", dynamicMiddleware.ThenFunc(app.home))
mux.Get("/snippet/create", dynamicMiddleware.ThenFunc(app.createSnippetForm))
mux.Post("/snippet/create", dynamicMiddleware.ThenFunc(app.createSnippet))
mux.Get("/snippet/:id", dynamicMiddleware.ThenFunc(app.showSnippet))
fileServer := http.FileServer(http.Dir("./ui/static/"))
mux.Get("/static/", http.StripPrefix("/static", fileServer))
return standardMiddleware.Then(mux)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment