1Panel/backend/init/router/router.go

42 lines
887 B
Go
Raw Normal View History

2022-08-16 15:30:23 +00:00
package router
import (
"github.com/1Panel-dev/1Panel/backend/i18n"
"github.com/1Panel-dev/1Panel/backend/middleware"
rou "github.com/1Panel-dev/1Panel/backend/router"
"github.com/gin-contrib/gzip"
2022-08-16 15:30:23 +00:00
"github.com/gin-gonic/gin"
)
var (
Router *gin.Engine
2022-08-16 15:30:23 +00:00
)
func setWebStatic(rootRouter *gin.RouterGroup) {
rootRouter.Static("/api/v1/images", "./uploads")
rootRouter.Use(func(c *gin.Context) {
c.Next()
})
2022-10-17 09:13:47 +00:00
}
2022-08-16 15:30:23 +00:00
func Routers() *gin.Engine {
Router = gin.Default()
2024-02-19 05:55:27 +00:00
Router.Use(i18n.UseI18n())
2022-08-16 15:30:23 +00:00
PublicGroup := Router.Group("")
{
PublicGroup.GET("/health", func(c *gin.Context) {
c.JSON(200, "ok")
})
PublicGroup.Use(gzip.Gzip(gzip.DefaultCompression))
setWebStatic(PublicGroup)
2022-08-16 15:30:23 +00:00
}
PrivateGroup := Router.Group("/api/v1")
2023-01-31 07:22:05 +00:00
PrivateGroup.Use(middleware.GlobalLoading())
for _, router := range rou.RouterGroupApp {
router.InitRouter(PrivateGroup)
2022-08-16 15:30:23 +00:00
}
return Router
}