69 lines
1.2 KiB
Go
69 lines
1.2 KiB
Go
package initialize
|
|
|
|
import (
|
|
"ai4m/global"
|
|
"ai4m/router"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type justFilesFilesystem struct {
|
|
fs http.FileSystem
|
|
}
|
|
|
|
func (fs justFilesFilesystem) Open(name string) (http.File, error) {
|
|
f, err := fs.fs.Open(name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
stat, err := f.Stat()
|
|
if stat.IsDir() {
|
|
return nil, os.ErrPermission
|
|
}
|
|
|
|
return f, nil
|
|
}
|
|
|
|
// 初始化总路由
|
|
|
|
func Routers() *gin.Engine {
|
|
Router := gin.New()
|
|
Router.Use(gin.Recovery())
|
|
if gin.Mode() == gin.DebugMode {
|
|
Router.Use(gin.Logger())
|
|
}
|
|
|
|
systemRouter := router.RouterGroupApp.System
|
|
|
|
// 方便统一添加路由组前缀 多服务器上线使用
|
|
|
|
PublicGroup := Router.Group(global.PCM_CONFIG.System.RouterPrefix)
|
|
|
|
PrivateGroup := Router.Group(global.PCM_CONFIG.System.RouterPrefix)
|
|
|
|
{
|
|
// 健康监测
|
|
PublicGroup.GET("/health", func(c *gin.Context) {
|
|
c.JSON(http.StatusOK, "ok")
|
|
})
|
|
}
|
|
|
|
{
|
|
systemRouter.InitScreenRouter(PublicGroup) // 注册功能api路由
|
|
systemRouter.InitSFTPRouter(PublicGroup)
|
|
|
|
}
|
|
|
|
//插件路由安装
|
|
InstallPlugin(PrivateGroup, PublicGroup, Router)
|
|
|
|
// 注册业务路由
|
|
initBizRouter(PrivateGroup, PublicGroup)
|
|
|
|
global.PCM_LOG.Info("router register success")
|
|
return Router
|
|
}
|