package handler import ( "net/http" "management/internal/erpserver/handler/auth" "management/internal/erpserver/handler/captcha" "management/internal/erpserver/handler/system" "management/internal/erpserver/handler/upload" v1 "management/internal/erpserver/service/v1" authv1 "management/internal/erpserver/service/v1/auth" "management/internal/pkg/config" "management/internal/pkg/mid" "management/internal/pkg/render" "management/internal/pkg/token" "management/internal/tasks" "github.com/drhin/logger" "github.com/gin-gonic/gin" ) type Config struct { Conf *config.Config Log *logger.Logger Token token.Maker Render render.Renderer TaskDistributor tasks.TaskDistributor CaptchaService v1.CaptchaService AuthService *authv1.Auth UserService v1.UserService RoleService v1.RoleService DepartmentService v1.DepartmentService MenuService v1.MenuService ConfigService v1.ConfigService AuditLogService v1.AuditLogService LoginLogService v1.LoginLogService } func WebApp(cfg Config) http.Handler { app := gin.New() app.Use(gin.Recovery()) if gin.Mode() == gin.DebugMode { app.Use(gin.Logger()) } //app.Static("/public/*", "./public/") publishApp := app.Group("") privateApp := app.Group("") privateApp.Use(mid.Authorize(cfg.Token, cfg.MenuService)) { // 健康监测 publishApp.GET("/health", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }) } { // 公共方法 captcha.Routes(publishApp, captcha.Config{ Conf: cfg.Conf, CaptchaService: cfg.CaptchaService, }) upload.Routes(privateApp, upload.Config{ Log: cfg.Log, }) } { // 登陆 auth.Routes(publishApp, privateApp, auth.Config{ Log: cfg.Log, CaptchaService: cfg.CaptchaService, AuthService: cfg.AuthService, UserService: cfg.UserService, MenuService: cfg.MenuService, }) } { // 后台管理 system.Routes(privateApp, system.Config{ RoleService: cfg.RoleService, MenuService: cfg.MenuService, AuditLogService: cfg.AuditLogService, LoginLogService: cfg.LoginLogService, ConfigService: cfg.ConfigService, }) } return app }