diff --git a/server/config.yaml b/server/config.yaml index fff9a988f..4a85fada6 100644 --- a/server/config.yaml +++ b/server/config.yaml @@ -43,6 +43,7 @@ system: addr: 8888 db-type: 'mysql' oss-type: 'local' # 控制oss选择走本地还是 七牛等其他仓 自行增加其他oss仓可以在 server/utils/upload/upload.go 中 NewOss函数配置 + use-redis: false # 使用redis use-multipoint: false # IP限制次数 一个小时15000次 iplimit-count: 15000 diff --git a/server/config/system.go b/server/config/system.go index 8cf92b060..5a8d22999 100644 --- a/server/config/system.go +++ b/server/config/system.go @@ -6,6 +6,7 @@ type System struct { DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"` // 数据库类型:mysql(默认)|sqlite|sqlserver|postgresql OssType string `mapstructure:"oss-type" json:"ossType" yaml:"oss-type"` // Oss类型 UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint" yaml:"use-multipoint"` // 多点登录拦截 + UseRedis bool `mapstructure:"use-redis" json:"useRedis" yaml:"use-redis"` // 使用redis LimitCountIP int `mapstructure:"iplimit-count" json:"iplimitCount" yaml:"iplimit-count"` LimitTimeIP int `mapstructure:"iplimit-time" json:"iplimitTime" yaml:"iplimit-time"` } diff --git a/server/core/server.go b/server/core/server.go index 05e0df0ed..8ddcd90bb 100644 --- a/server/core/server.go +++ b/server/core/server.go @@ -15,7 +15,7 @@ type server interface { } func RunWindowsServer() { - if global.GVA_CONFIG.System.UseMultipoint { + if global.GVA_CONFIG.System.UseMultipoint || global.GVA_CONFIG.System.UseRedis { // 初始化redis服务 initialize.Redis() } @@ -26,7 +26,6 @@ func RunWindowsServer() { } Router := initialize.Routers() - Router.Static("/form-generator", "./resource/page") address := fmt.Sprintf(":%d", global.GVA_CONFIG.System.Addr) diff --git a/server/initialize/router.go b/server/initialize/router.go index 52b956e52..9f5427c2f 100644 --- a/server/initialize/router.go +++ b/server/initialize/router.go @@ -27,7 +27,7 @@ func Routers() *gin.Engine { // Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面 Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.Path)) // 为用户头像和文件提供静态地址 - // Router.Use(middleware.LoadTls()) // 打开就能玩https了 + // Router.Use(middleware.LoadTls()) // 如果需要使用https 请打开此中间件 然后前往 core/server.go 将启动模式 更变为 Router.RunTLS("端口","你的cre/pem文件","你的key文件") global.GVA_LOG.Info("use middleware logger") // 跨域,如需跨域可以打开下面的注释 // Router.Use(middleware.Cors()) // 直接放行全部跨域请求 diff --git a/server/model/system/sys_casbin.go b/server/model/system/sys_casbin.go deleted file mode 100644 index d205bb959..000000000 --- a/server/model/system/sys_casbin.go +++ /dev/null @@ -1,8 +0,0 @@ -package system - -type CasbinModel struct { - Ptype string `json:"ptype" gorm:"column:ptype"` - AuthorityId string `json:"rolename" gorm:"column:v0"` - Path string `json:"path" gorm:"column:v1"` - Method string `json:"method" gorm:"column:v2"` -} diff --git a/server/service/system/sys_casbin.go b/server/service/system/sys_casbin.go index 1800e912e..944cb1d1f 100644 --- a/server/service/system/sys_casbin.go +++ b/server/service/system/sys_casbin.go @@ -7,7 +7,6 @@ import ( "github.com/casbin/casbin/v2" gormadapter "github.com/casbin/gorm-adapter/v3" "github.com/flipped-aurora/gin-vue-admin/server/global" - "github.com/flipped-aurora/gin-vue-admin/server/model/system" "github.com/flipped-aurora/gin-vue-admin/server/model/system/request" _ "github.com/go-sql-driver/mysql" ) @@ -26,13 +25,7 @@ func (casbinService *CasbinService) UpdateCasbin(authorityId string, casbinInfos casbinService.ClearCasbin(0, authorityId) rules := [][]string{} for _, v := range casbinInfos { - cm := system.CasbinModel{ - Ptype: "p", - AuthorityId: authorityId, - Path: v.Path, - Method: v.Method, - } - rules = append(rules, []string{cm.AuthorityId, cm.Path, cm.Method}) + rules = append(rules, []string{authorityId, v.Path, v.Method}) } e := casbinService.Casbin() success, _ := e.AddPolicies(rules) @@ -49,7 +42,7 @@ func (casbinService *CasbinService) UpdateCasbin(authorityId string, casbinInfos //@return: error func (casbinService *CasbinService) UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error { - err := global.GVA_DB.Table("casbin_rule").Model(&system.CasbinModel{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]interface{}{ + err := global.GVA_DB.Model(&gormadapter.CasbinRule{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]interface{}{ "v1": newPath, "v2": newMethod, }).Error