You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Initialize a Beego ORM adapter and use it in a Casbin enforcer:
29
-
// The adapter will use the MySQL database named "casbin".
30
-
// If it doesn't exist, the adapter will create it automatically.
31
-
a:= beegoormadapter.NewAdapter("mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/") // Your driver and data source.
32
-
33
-
// Or you can use an existing DB "abc" like this:
34
-
// The adapter will use the table named "casbin_rule".
35
-
// If it doesn't exist, the adapter will create it automatically.
36
-
// a := beegoormadapter.NewAdapter("mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/abc", true)
37
-
38
-
e:= casbin.NewEnforcer("examples/rbac_model.conf", a)
39
-
40
-
// Load the policy from DB.
41
-
e.LoadPolicy()
42
-
31
+
a, err:= beegoormadapter.NewAdapter("default", "mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/dbname") // Your driver and data source.
32
+
if err != nil {
33
+
log.Fatalln(err)
34
+
}
35
+
36
+
e, err:= casbin.NewEnforcer("examples/rbac_model.conf", a)
37
+
if err != nil {
38
+
log.Fatalln(err)
39
+
}
43
40
// Check the permission.
44
41
e.Enforce("alice", "data1", "read")
45
42
@@ -52,45 +49,6 @@ func main() {
52
49
}
53
50
```
54
51
55
-
## Simple Postgres Example
56
-
57
-
```go
58
-
package main
59
-
60
-
import (
61
-
"github.com/casbin/beego-orm-adapter"
62
-
"github.com/casbin/casbin"
63
-
_ "github.com/lib/pq"
64
-
)
65
-
66
-
funcmain() {
67
-
// Initialize a Beego ORM adapter and use it in a Casbin enforcer:
68
-
// The adapter will use the Postgres database named "casbin".
69
-
// If it doesn't exist, the adapter will create it automatically.
70
-
a:= beegoormadapter.NewAdapter("postgres", "user=postgres_username password=postgres_password host=127.0.0.1 port=5432 sslmode=disable") // Your driver and data source.
71
-
72
-
// Or you can use an existing DB "abc" like this:
73
-
// The adapter will use the table named "casbin_rule".
74
-
// If it doesn't exist, the adapter will create it automatically.
0 commit comments