Files
mygo/internal/server/router.go
Huxley 7fb125ea87 Implement web API foundation
Add application container, Gin router, graceful shutdown handler,
and version endpoint. This establishes the skeleton for the WebDisk
HTTP API as described in the architecture.

- Add internal/app/WebApp for runtime dependencies and version
- Add internal/server/router with GET /api/v1/version route
- Add graceful shutdown runner with signal handling in cmd/serve
- Add internal/api/ErrorResponse for standard HTTP error body
- Update roadmap, architecture, and decisions documentation
2026-04-27 23:06:06 +08:00

33 lines
750 B
Go

package server
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")
publicGroup := rootGroup.Group("")
setupVersionRoutes(publicGroup, handler.NewVersionHandler(webApp.Version))
authGroup := rootGroup.Group("")
setupProtectedRoutes(authGroup)
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
}