Add structured logging and centralized error handling
- Initialize slog in the serve command with terminal/file support - Introduce `AppError` with HTTP status for unified service-layer errors - Replace ad-hoc `api.Error` calls with `api.RespondError` - Wrap internal errors with `model.NewInternalError` and add reference IDs - Add `RequestID` middleware and switch router from `gin.Default` to `gin.New`
This commit is contained in:
@@ -4,11 +4,18 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/dhao2001/mygo/internal/app"
|
||||
"github.com/dhao2001/mygo/internal/middleware"
|
||||
)
|
||||
|
||||
// NewRouter builds the Gin router and registers API routes.
|
||||
func NewRouter(webApp *app.WebApp) *gin.Engine {
|
||||
router := gin.Default()
|
||||
router := gin.New()
|
||||
|
||||
// Request ID must be first — every subsequent middleware and handler
|
||||
// gets access to req_id in the context.
|
||||
router.Use(middleware.RequestID())
|
||||
router.Use(gin.Logger())
|
||||
router.Use(gin.Recovery())
|
||||
|
||||
v1 := router.Group("/api/v1")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user