StreamBox/internal/router/router.go

36 lines
756 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package router
import (
"github.com/gin-gonic/gin"
"streambox/config"
"streambox/internal/handler"
"streambox/internal/middleware"
"streambox/internal/repo"
"streambox/internal/service"
)
func New(cfg *config.Config) *gin.Engine {
gin.SetMode(cfg.Server.Mode)
r := gin.New()
r.Use(middleware.Recovery())
r.Use(middleware.ZapLogger())
r.Use(middleware.Cors(cfg.Cors))
// 健康检查(不带前缀,方便探活)
health := handler.NewHealthHandler()
r.GET("/health", health.Check)
// 依赖注入:repo -> service -> handler
pingRepo := repo.NewPingRepo()
pingSvc := service.NewPingService(pingRepo)
pingHandler := handler.NewPingHandler(pingSvc)
v1 := r.Group("/api/v1")
{
v1.GET("/ping", pingHandler.Ping)
}
return r
}