2024-01-25 00:14:33 +00:00
|
|
|
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"
|
2024-01-25 00:14:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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()
|
2024-01-25 00:14:33 +00:00
|
|
|
|
|
|
|
// 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-25 00:14:33 +00:00
|
|
|
|
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-25 00:14:33 +00:00
|
|
|
|
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)
|
2024-01-25 00:14:33 +00:00
|
|
|
}
|