ch7.2
This commit is contained in:
@@ -3,20 +3,26 @@ package main
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/justinas/alice"
|
||||
)
|
||||
|
||||
func (app *application) routes() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
router := httprouter.New()
|
||||
|
||||
router.NotFound = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
app.notFound(w)
|
||||
})
|
||||
|
||||
fileServer := http.FileServer(http.Dir("./ui/static/"))
|
||||
mux.Handle("/static/", http.StripPrefix("/static", fileServer))
|
||||
router.Handler(http.MethodGet, "/static/", http.StripPrefix("/static", fileServer))
|
||||
|
||||
mux.HandleFunc("/", app.home)
|
||||
mux.HandleFunc("/snippet/view", app.snippetView)
|
||||
mux.HandleFunc("/snippet/create", app.snippetCreate)
|
||||
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(mux)
|
||||
return standard.Then(router)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user