Skip to content

Commit f00c9d5

Browse files
committed
Add support for Casbin v2.0.0
start using go modules and mark this version as v2 to indicate casbin v2 compatibility.
1 parent 98e846e commit f00c9d5

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ JSON Adapter is the [JSON (JavaScript Object Notation)](https://www.json.org/) a
1313
package main
1414

1515
import (
16-
"github.com/casbin/casbin"
17-
"github.com/casbin/json-adapter"
16+
"github.com/casbin/casbin/v2"
17+
"github.com/casbin/json-adapter/v2"
1818
)
1919

2020
func main() {
2121
// Initialize a JSON adapter and use it in a Casbin enforcer:
2222
b := []byte{} // b stores Casbin policy in JSON bytes.
2323
a := jsonadapter.NewAdapter(&b) // Use b as the data source.
24-
e := casbin.NewEnforcer("examples/rbac_model.conf", a)
24+
e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a)
2525

2626
// Load the policy from JSON bytes b.
2727
e.LoadPolicy()

adapter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"encoding/json"
1919
"errors"
2020

21-
"github.com/casbin/casbin/model"
22-
"github.com/casbin/casbin/persist"
21+
"github.com/casbin/casbin/v2/model"
22+
"github.com/casbin/casbin/v2/persist"
2323
)
2424

2525
type CasbinRule struct {

adapter_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"log"
1919
"testing"
2020

21-
"github.com/casbin/casbin"
22-
"github.com/casbin/casbin/util"
21+
"github.com/casbin/casbin/v2"
22+
"github.com/casbin/casbin/v2/util"
2323
)
2424

2525
func testGetPolicy(t *testing.T, e *casbin.Enforcer, res [][]string) {
@@ -34,7 +34,7 @@ func testGetPolicy(t *testing.T, e *casbin.Enforcer, res [][]string) {
3434
func TestAdapter(t *testing.T) {
3535
// Because the JSON Buffer is empty at first,
3636
// so we need to load the policy from the file adapter (.CSV) first.
37-
e := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
37+
e, _ := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
3838

3939
b := []byte{}
4040
a := NewAdapter(&b)
@@ -58,6 +58,6 @@ func TestAdapter(t *testing.T) {
5858
// Create an adapter and an enforcer.
5959
// NewEnforcer() will load the policy automatically.
6060
a = NewAdapter(&b)
61-
e = casbin.NewEnforcer("examples/rbac_model.conf", a)
61+
e, _ = casbin.NewEnforcer("examples/rbac_model.conf", a)
6262
testGetPolicy(t, e, [][]string{{"alice", "data1", "read"}, {"bob", "data2", "write"}, {"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}})
6363
}

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/casbin/json-adapter/v2
2+
3+
go 1.12
4+
5+
require github.com/casbin/casbin/v2 v2.0.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw=
2+
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
3+
github.com/casbin/casbin/v2 v2.0.0 h1:OIcnP8SxwF1gmGxOn7Kod/O/7yJikpHWQz0qiBJpG/U=
4+
github.com/casbin/casbin/v2 v2.0.0/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=

0 commit comments

Comments
 (0)