learn-go/snippetbox/cmd/web/routes.go

27 lines
767 B
Go
Raw Normal View History

package main
import (
"net/http"
2024-01-26 00:27:56 +00:00
2024-01-26 06:01:12 +00:00
"github.com/julienschmidt/httprouter"
2024-01-26 00:27:56 +00:00
"github.com/justinas/alice"
)
// routes ...
2024-01-25 23:43:07 +00:00
func (app *application) routes() http.Handler {
2024-01-26 06:01:12 +00:00
router := httprouter.New()
// setup server for static files
fileServer := http.FileServer(http.Dir("./ui/static"))
2024-01-26 06:01:12 +00:00
router.Handler(http.MethodGet, "/static/*filepath", http.StripPrefix("/static", fileServer))
2024-01-26 06:01:12 +00:00
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)
2024-01-26 00:27:56 +00:00
standard := alice.New(app.recoverPanic, app.logRequest, secureHeaders)
2024-01-26 06:01:12 +00:00
return standard.Then(router)
}