32 lines
573 B
Go
32 lines
573 B
Go
package httpx
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"senlinai-agent/backend/internal/config"
|
|
)
|
|
|
|
type RouteRegistrar interface {
|
|
Register(router gin.IRouter)
|
|
}
|
|
|
|
func NewRouter(cfg config.Config, registrars ...RouteRegistrar) *gin.Engine {
|
|
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"})
|
|
})
|
|
api := router.Group("/api")
|
|
for _, registrar := range registrars {
|
|
registrar.Register(api)
|
|
}
|
|
|
|
return router
|
|
}
|