1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package initialize
- import (
- "github.com/gin-gonic/gin"
- swaggerFiles "github.com/swaggo/files"
- ginSwagger "github.com/swaggo/gin-swagger"
- "net/http"
- "os"
- "server/docs"
- "server/global"
- "server/middleware"
- "server/router"
- )
- 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())
- }
- InstallPlugin(Router)
- systemRouter := router.RouterGroupApp.System
- exampleRouter := router.RouterGroupApp.Example
- adminRouter := router.RouterGroupApp.Admin
-
-
-
-
-
-
-
- Router.StaticFS(global.GVA_CONFIG.Local.StorePath, justFilesFilesystem{http.Dir(global.GVA_CONFIG.Local.StorePath)})
-
-
-
-
- docs.SwaggerInfo.BasePath = global.GVA_CONFIG.System.RouterPrefix
- Router.GET(global.GVA_CONFIG.System.RouterPrefix+"/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
- global.GVA_LOG.Info("register swagger handler")
-
- PublicGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix)
- {
-
- PublicGroup.GET("/health", func(c *gin.Context) {
- c.JSON(http.StatusOK, "ok")
- })
- }
- {
- systemRouter.InitBaseRouter(PublicGroup)
- }
- PrivateGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix)
- PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
- {
- systemRouter.InitApiRouter(PrivateGroup, PublicGroup)
- systemRouter.InitJwtRouter(PrivateGroup)
- systemRouter.InitUserRouter(PrivateGroup)
- systemRouter.InitMenuRouter(PrivateGroup)
- systemRouter.InitCasbinRouter(PrivateGroup)
- systemRouter.InitAuthorityRouter(PrivateGroup)
- systemRouter.InitSysDictionaryRouter(PrivateGroup)
- systemRouter.InitSysOperationRecordRouter(PrivateGroup)
- systemRouter.InitSysDictionaryDetailRouter(PrivateGroup)
- systemRouter.InitAuthorityBtnRouterRouter(PrivateGroup)
- exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup)
- adminRouter.InitDeviceRouter(PrivateGroup)
- adminRouter.InitDeviceGenreRouter(PrivateGroup)
- adminRouter.InitRegionRouter(PrivateGroup)
- adminRouter.InitTunnelRouter(PrivateGroup)
- }
- global.GVA_LOG.Info("router register success")
- return Router
- }
|