Browse Source

fix: remove casbin init single case

main
SliverHorn 4 years ago
parent
commit
5ffc56dc35
  1. 19
      server/service/sys_casbin.go

19
server/service/sys_casbin.go

@ -5,13 +5,11 @@ import (
"gin-vue-admin/global" "gin-vue-admin/global"
"gin-vue-admin/model" "gin-vue-admin/model"
"gin-vue-admin/model/request" "gin-vue-admin/model/request"
"strings"
"sync"
"github.com/casbin/casbin/v2" "github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/util" "github.com/casbin/casbin/v2/util"
gormadapter "github.com/casbin/gorm-adapter/v3" gormadapter "github.com/casbin/gorm-adapter/v3"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"strings"
) )
//@author: [piexlmax](https://github.com/piexlmax) //@author: [piexlmax](https://github.com/piexlmax)
@ -90,18 +88,11 @@ func ClearCasbin(v int, p ...string) bool {
//@description: 持久化到数据库 引入自定义规则 //@description: 持久化到数据库 引入自定义规则
//@return: *casbin.Enforcer //@return: *casbin.Enforcer
var (
e *casbin.Enforcer
once sync.Once
)
func Casbin() *casbin.Enforcer { func Casbin() *casbin.Enforcer {
once.Do(func() {
a, _ := gormadapter.NewAdapterByDB(global.GVA_DB)
e, _ = casbin.NewEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a)
e.AddFunction("ParamsMatch", ParamsMatchFunc)
_ = e.LoadPolicy()
})
a, _ := gormadapter.NewAdapterByDB(global.GVA_DB)
e, _ := casbin.NewEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a)
e.AddFunction("ParamsMatch", ParamsMatchFunc)
_ = e.LoadPolicy()
return e return e
} }

Loading…
Cancel
Save