Update structure to domain driven architecture.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
)
|
||||
|
||||
func (s *Server) setupRoutes() *chi.Mux {
|
||||
router := chi.NewRouter()
|
||||
|
||||
// Global Middleware
|
||||
router.Use(middleware.RequestID)
|
||||
router.Use(middleware.RealIP)
|
||||
router.Use(s.logRequest)
|
||||
router.Use(middleware.Recoverer)
|
||||
|
||||
// Public routes
|
||||
router.Group(func(r chi.Router) {
|
||||
// Auth Routes
|
||||
router.Post("/register", s.handleRegister())
|
||||
router.Post("/login", s.handleLogin())
|
||||
router.Post("/logout", s.handleLogout())
|
||||
router.Post("/refresh", s.handleRefresh())
|
||||
})
|
||||
|
||||
// Private routes
|
||||
router.Group(func(r chi.Router) {
|
||||
// Requires log in
|
||||
r.Use(s.hasAuth)
|
||||
|
||||
// TODO add authenicated routes here
|
||||
r.Get("/home", s.handleHome())
|
||||
// router.Mount("/api", s.apiRoutes())
|
||||
})
|
||||
|
||||
return router
|
||||
}
|
||||
Reference in New Issue
Block a user