Files
agent/backend/internal/httpx/router.go

32 lines
573 B
Go
Raw Normal View History

2026-07-18 15:50:04 +08:00
package httpx
import (
"net/http"
"github.com/gin-gonic/gin"
"senlinai-agent/backend/internal/config"
)
2026-07-18 17:42:50 +08:00
type RouteRegistrar interface {
Register(router gin.IRouter)
}
func NewRouter(cfg config.Config, registrars ...RouteRegistrar) *gin.Engine {
2026-07-18 15:50:04 +08:00
if cfg.Env == "test" {
gin.SetMode(gin.TestMode)
}
router := gin.New()
router.Use(gin.Recovery())
router.GET("/healthz", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})
2026-07-18 17:42:50 +08:00
api := router.Group("/api")
for _, registrar := range registrars {
registrar.Register(api)
}
2026-07-18 15:50:04 +08:00
return router
}