Refactor router setup to split routes by auth/protected boundary
This commit is contained in:
@@ -4,29 +4,16 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/dhao2001/mygo/internal/app"
|
||||
"github.com/dhao2001/mygo/internal/handler"
|
||||
)
|
||||
|
||||
// NewRouter builds the Gin router and registers API routes.
|
||||
func NewRouter(webApp *app.WebApp) *gin.Engine {
|
||||
router := gin.Default()
|
||||
|
||||
rootGroup := router.Group("/api/v1")
|
||||
v1 := router.Group("/api/v1")
|
||||
|
||||
publicGroup := rootGroup.Group("")
|
||||
setupVersionRoutes(publicGroup, handler.NewVersionHandler(webApp.Version))
|
||||
|
||||
authGroup := rootGroup.Group("")
|
||||
setupProtectedRoutes(authGroup)
|
||||
setupPublicRoutes(v1, webApp)
|
||||
setupProtectedRoutes(v1, webApp)
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
func setupVersionRoutes(rg *gin.RouterGroup, h *handler.VersionHandler) {
|
||||
rg.GET("/version", h.Get)
|
||||
}
|
||||
|
||||
func setupProtectedRoutes(rg *gin.RouterGroup) {
|
||||
// Protected routes will be registered after auth middleware exists.
|
||||
_ = rg
|
||||
}
|
||||
|
||||
12
internal/server/routes_protected.go
Normal file
12
internal/server/routes_protected.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/dhao2001/mygo/internal/app"
|
||||
)
|
||||
|
||||
func setupProtectedRoutes(rg *gin.RouterGroup, _ *app.WebApp) {
|
||||
_ = rg
|
||||
// Protected routes will be registered after auth middleware is implemented.
|
||||
}
|
||||
13
internal/server/routes_public.go
Normal file
13
internal/server/routes_public.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/dhao2001/mygo/internal/app"
|
||||
"github.com/dhao2001/mygo/internal/handler"
|
||||
)
|
||||
|
||||
func setupPublicRoutes(rg *gin.RouterGroup, webApp *app.WebApp) {
|
||||
versionHandler := handler.NewVersionHandler(webApp.Version)
|
||||
rg.GET("/version", versionHandler.Get)
|
||||
}
|
||||
Reference in New Issue
Block a user