-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: improve test readability and include README.md --------- Co-authored-by: Luis Albarenga <luisalbarenga@Luiss-MacBook-Pro-2.local>
- Loading branch information
Showing
2 changed files
with
98 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Usage | ||
Simple example: | ||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/casbin/casbin/v2" | ||
"github.com/labstack/echo/v4" | ||
casbin_mw "github.com/labstack/echo-contrib/casbin" | ||
) | ||
|
||
func main() { | ||
e := echo.New() | ||
|
||
// Mediate the access for every request | ||
e.Use(casbin_mw.Middleware(casbin.NewEnforcer("auth_model.conf", "auth_policy.csv"))) | ||
|
||
e.Logger.Fatal(e.Start(":1323")) | ||
} | ||
``` | ||
|
||
Advanced example: | ||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/casbin/casbin/v2" | ||
"github.com/labstack/echo/v4" | ||
casbin_mw "github.com/labstack/echo-contrib/casbin" | ||
) | ||
|
||
func main() { | ||
ce, _ := casbin.NewEnforcer("auth_model.conf", "") | ||
ce.AddRoleForUser("alice", "admin") | ||
ce.AddPolicy("added_user", "data1", "read") | ||
|
||
e := echo.New() | ||
|
||
e.Use(casbin_mw.Middleware(ce)) | ||
|
||
e.Logger.Fatal(e.Start(":1323")) | ||
} | ||
``` | ||
|
||
# API Reference | ||
See [API Overview](https://casbin.org/docs/api-overview). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters