采用中间件授权的方式

This commit is contained in:
RockYang
2025-08-26 10:45:57 +08:00
parent fb76e24c51
commit 728de61bd6
43 changed files with 527 additions and 484 deletions

View File

@@ -11,6 +11,7 @@ import (
"encoding/json"
"errors"
"geekai/core"
"geekai/core/middleware"
"geekai/core/types"
"geekai/handler"
"geekai/service"
@@ -42,12 +43,17 @@ func NewConfigHandler(app *core.AppServer, db *gorm.DB, levelDB *store.LevelDB,
// RegisterRoutes 注册路由
func (h *ConfigHandler) RegisterRoutes() {
group := h.App.Engine.Group("/api/admin/config")
group.POST("update", h.Update)
group.GET("get", h.Get)
group.POST("active", h.Active)
group.POST("test", h.Test)
group.GET("license", h.GetLicense)
group := h.App.Engine.Group("/api/admin/config/")
// 需要管理员授权的接口
group.Use(middleware.AdminAuthMiddleware(h.App.Config.AdminSession.SecretKey, h.App.Redis))
{
group.POST("update", h.Update)
group.GET("get", h.Get)
group.POST("active", h.Active)
group.POST("test", h.Test)
group.GET("license", h.GetLicense)
}
}
func (h *ConfigHandler) Update(c *gin.Context) {