Skip to content

Commit

Permalink
Adapt to goframe v2.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dobyte committed Mar 1, 2023
1 parent b410f0c commit 7c4ca6f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
7 changes: 4 additions & 3 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/casbin/casbin/v2/model"
"github.com/casbin/casbin/v2/persist"
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
"github.com/gogf/gf/v2/database/gdb"
)

Expand Down Expand Up @@ -255,7 +256,7 @@ func (a *adapter) UpdatePolicies(sec string, ptype string, oldRules, newRules []
return
}

err = a.db.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
err = a.db.Transaction(context.TODO(), func(ctx context.Context, tx gdb.TX) error {
for i := 0; i < int(math.Min(float64(len(oldRules)), float64(len(newRules)))); i++ {
if _, err = tx.Model(a.table).Update(a.buildPolicyRule(ptype, newRules[i]), a.buildPolicyRule(ptype, oldRules[i])); err != nil {
return err
Expand All @@ -268,7 +269,7 @@ func (a *adapter) UpdatePolicies(sec string, ptype string, oldRules, newRules []
return
}

// 加载策略规则
// load a policy rule
func (a *adapter) loadPolicyRule(rule policyRule, model model.Model) {
ruleText := rule.PType

Expand Down Expand Up @@ -299,7 +300,7 @@ func (a *adapter) loadPolicyRule(rule policyRule, model model.Model) {
persist.LoadPolicyLine(ruleText, model)
}

// 构建策略规则
// build a policy rule.
func (a *adapter) buildPolicyRule(ptype string, data []string) policyRule {
rule := policyRule{PType: ptype}

Expand Down
30 changes: 28 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
module github.com/dobyte/gf-casbin

go 1.16
go 1.17

require (
github.com/casbin/casbin/v2 v2.41.0
github.com/gogf/gf/v2 v2.0.0
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.3.2
github.com/gogf/gf/v2 v2.3.2
)

require (
github.com/BurntSushi/toml v1.1.0 // indirect
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
github.com/clbanning/mxj/v2 v2.5.5 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

0 comments on commit 7c4ca6f

Please sign in to comment.