Using chi for routing

This commit is contained in:
Muyao CHEN 2024-06-28 13:14:05 +02:00
parent daef31f070
commit e1b990dfd3
3 changed files with 13 additions and 5 deletions

View File

@ -5,14 +5,17 @@ import (
"go-udemy-web-1/pkg/handlers" "go-udemy-web-1/pkg/handlers"
"net/http" "net/http"
"github.com/bmizerany/pat" "github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
) )
func routes(app *config.AppConfig) http.Handler { func routes(app *config.AppConfig) http.Handler {
mux := pat.New() mux := chi.NewMux()
mux.Get("/", http.HandlerFunc(handlers.Repo.Home)) mux.Use(middleware.Recoverer)
mux.Get("/about", http.HandlerFunc(handlers.Repo.About))
mux.Get("/", handlers.Repo.Home)
mux.Get("/about", handlers.Repo.About)
return mux return mux
} }

5
go.mod
View File

@ -2,4 +2,7 @@ module go-udemy-web-1
go 1.21.0 go 1.21.0
require github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f // indirect require (
github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f // indirect
github.com/go-chi/chi/v5 v5.0.14 // indirect
)

2
go.sum
View File

@ -1,2 +1,4 @@
github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f h1:gOO/tNZMjjvTKZWpY7YnXC72ULNLErRtp94LountVE8= github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f h1:gOO/tNZMjjvTKZWpY7YnXC72ULNLErRtp94LountVE8=
github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/go-chi/chi/v5 v5.0.14 h1:PyEwo2Vudraa0x/Wl6eDRRW2NXBvekgfxyydcM0WGE0=
github.com/go-chi/chi/v5 v5.0.14/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=