2022-08-16 15:30:23 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
2022-10-17 08:32:31 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/i18n"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/middleware"
|
|
|
|
rou "github.com/1Panel-dev/1Panel/backend/router"
|
2023-12-20 14:44:09 +00:00
|
|
|
"github.com/gin-contrib/gzip"
|
2022-08-16 15:30:23 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
2023-12-20 14:44:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
Router *gin.Engine
|
2022-08-16 15:30:23 +00:00
|
|
|
)
|
|
|
|
|
2023-05-29 16:00:56 +00:00
|
|
|
func setWebStatic(rootRouter *gin.RouterGroup) {
|
2024-03-27 10:34:07 +00:00
|
|
|
rootRouter.Static("/api/v1/images", "./uploads")
|
2023-11-09 02:44:15 +00:00
|
|
|
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 {
|
2023-12-20 14:44:09 +00:00
|
|
|
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")
|
|
|
|
})
|
2023-05-29 16:00:56 +00:00
|
|
|
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())
|
2023-12-20 14:44:09 +00:00
|
|
|
for _, router := range rou.RouterGroupApp {
|
|
|
|
router.InitRouter(PrivateGroup)
|
2022-08-16 15:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Router
|
|
|
|
}
|