Skip to content

Commit b597602

Browse files
1 parent 5f6d795 commit b597602

File tree

42 files changed

+532
-3829
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+532
-3829
lines changed

docs/contrib/README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ Repository for third party middlewares and service implementations, with depende
1919

2020
## 📑 Middleware Implementations
2121

22-
* [casbin](./v3/casbin/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+Casbin%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-casbin.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="casbin workflow status" /> </a>
23-
* [circuitbreaker](./v3/circuitbreaker/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+CircuitBreaker%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-circuitbreaker.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="circuitbreaker workflow status" /> </a>
24-
* [fgprof](./v3/fgprof/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+Fgprof%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-fgprof.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="fgprof workflow status" /> </a>
25-
* [i18n](./v3/i18n/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+i18n%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-i18n.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="i18n workflow status" /> </a>
26-
* [sentry](./v3/sentry/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+sentry%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-sentry.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="sentry workflow status" /> </a>
27-
* [zap](./v3/zap/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+zap%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-zap.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="zap workflow status" /> </a>
28-
* [zerolog](./v3/zerolog/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+zerolog%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-zerolog.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="zerolog workflow status" /> </a>
29-
* [hcaptcha](./v3/hcaptcha/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+hcaptcha%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-hcaptcha.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="hcaptcha workflow status" /> </a>
30-
* [jwt](./v3/jwt/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+jwt%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-jwt.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="jwt workflow status" /> </a>
31-
* [loadshed](./v3/loadshed/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+loadshed%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-loadshed.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="loadshed workflow status" /> </a>
32-
* [new relic](./v3/newrelic/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+newrelic%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-newrelic.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="new relic workflow status" /> </a>
33-
* [monitor](./v3/monitor/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+Monitor%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-monitor.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="monitor workflow status" /> </a>
34-
* [open policy agent](./v3/opa/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+opa%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-opa.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="OPA workflow status" /> </a>
35-
* [otel (opentelemetry)](./v3/otel/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+otel%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-otel.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="otel workflow status" /> </a>
36-
* [paseto](./v3/paseto/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+paseto%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-paseto.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="paseto workflow status" /> </a>
37-
* [socket.io](./v3/socketio/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+socketio%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-socketio.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="socket.io workflow status" /> </a>
38-
* [swagger](./v3/swagger/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+swagger%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-swagger.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="swagger workflow status" /> </a>
39-
* [websocket](./v3/websocket/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+websocket%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-websocket.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="websocket workflow status" /> </a>
22+
* [casbin](./casbin/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+Casbin%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-casbin.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="casbin workflow status" /> </a>
23+
* [circuitbreaker](./circuitbreaker/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+CircuitBreaker%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-circuitbreaker.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="circuitbreaker workflow status" /> </a>
24+
* [fgprof](./fgprof/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+Fgprof%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-fgprof.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="fgprof workflow status" /> </a>
25+
* [i18n](./i18n/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+i18n%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-i18n.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="i18n workflow status" /> </a>
26+
* [sentry](./sentry/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+sentry%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-sentry.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="sentry workflow status" /> </a>
27+
* [zap](./zap/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+zap%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-zap.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="zap workflow status" /> </a>
28+
* [zerolog](./zerolog/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+zerolog%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-zerolog.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="zerolog workflow status" /> </a>
29+
* [hcaptcha](./hcaptcha/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+hcaptcha%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-hcaptcha.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="hcaptcha workflow status" /> </a>
30+
* [jwt](./jwt/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+jwt%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-jwt.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="jwt workflow status" /> </a>
31+
* [loadshed](./loadshed/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+loadshed%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-loadshed.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="loadshed workflow status" /> </a>
32+
* [new relic](./newrelic/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+newrelic%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-newrelic.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="new relic workflow status" /> </a>
33+
* [monitor](./monitor/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+Monitor%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-monitor.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="monitor workflow status" /> </a>
34+
* [open policy agent](./opa/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+opa%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-opa.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="OPA workflow status" /> </a>
35+
* [otel (opentelemetry)](./otel/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+otel%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-otel.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="otel workflow status" /> </a>
36+
* [paseto](./paseto/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+paseto%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-paseto.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="paseto workflow status" /> </a>
37+
* [socket.io](./socketio/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+socketio%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-socketio.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="socket.io workflow status" /> </a>
38+
* [swagger](./swagger/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+swagger%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-swagger.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="swagger workflow status" /> </a>
39+
* [websocket](./websocket/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+websocket%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-websocket.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="websocket workflow status" /> </a>
4040

4141
## 🥡 Service Implementations
4242

43-
* [testcontainers](./v3/testcontainers/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+Testcontainers%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-testcontainers.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="testcontainers workflow status" /> </a>
43+
* [testcontainers](./testcontainers/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+Testcontainers%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-testcontainers.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="testcontainers workflow status" /> </a>

docs/contrib/casbin/README.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ id: casbin
1010

1111
Casbin middleware for Fiber.
1212

13-
**Note: Requires Go 1.18 and above**
13+
**Compatible with Fiber v3.**
14+
15+
## Go version support
16+
17+
We only support the latest two versions of Go. Visit [https://go.dev/doc/devel/release](https://go.dev/doc/devel/release) for more information.
1418

1519
## Install
16-
```
17-
go get -u github.com/gofiber/fiber/v2
18-
go get -u github.com/gofiber/contrib/casbin
20+
```sh
21+
go get -u github.com/gofiber/fiber/v3
22+
go get -u github.com/gofiber/contrib/v3/casbin
1923
```
2024
choose an adapter from [here](https://casbin.org/docs/adapters)
21-
```
25+
```sh
2226
go get -u github.com/casbin/xorm-adapter
2327
```
2428

@@ -29,27 +33,27 @@ casbin.New(config ...casbin.Config) *casbin.Middleware
2933

3034
## Config
3135

32-
| Property | Type | Description | Default |
33-
|:--------------|:--------------------------|:-----------------------------------------|:--------------------------------------------------------------------|
34-
| ModelFilePath | `string` | Model file path | `"./model.conf"` |
36+
| Property | Type | Description | Default |
37+
|:--------------|:--------------------------|:-----------------------------------------|:--------------------------------------------------------------|
38+
| ModelFilePath | `string` | Model file path | `"./model.conf"` |
3539
| PolicyAdapter | `persist.Adapter` | Database adapter for policies | `./policy.csv` |
3640
| Enforcer | `*casbin.Enforcer` | Custom casbin enforcer | `Middleware generated enforcer using ModelFilePath & PolicyAdapter` |
37-
| Lookup | `func(*fiber.Ctx) string` | Look up for current subject | `""` |
38-
| Unauthorized | `func(*fiber.Ctx) error` | Response body for unauthorized responses | `Unauthorized` |
39-
| Forbidden | `func(*fiber.Ctx) error` | Response body for forbidden responses | `Forbidden` |
41+
| Lookup | `func(fiber.Ctx) string` | Look up for current subject | `""` |
42+
| Unauthorized | `func(fiber.Ctx) error` | Response body for unauthorized responses | `Unauthorized` |
43+
| Forbidden | `func(fiber.Ctx) error` | Response body for forbidden responses | `Forbidden` |
4044

4145
### Examples
4246
- [Gorm Adapter](https://github.com/svcg/-fiber_casbin_demo)
43-
- [File Adapter](https://github.com/gofiber/contrib/casbin/tree/master/example)
47+
- [File Adapter](https://github.com/gofiber/contrib/tree/master/v3/casbin/example)
4448

4549
## CustomPermission
4650

4751
```go
4852
package main
4953

5054
import (
51-
"github.com/gofiber/fiber/v2"
52-
"github.com/gofiber/contrib/casbin"
55+
"github.com/gofiber/fiber/v3"
56+
"github.com/gofiber/contrib/v3/casbin"
5357
_ "github.com/go-sql-driver/mysql"
5458
"github.com/casbin/xorm-adapter/v2"
5559
)
@@ -60,21 +64,21 @@ func main() {
6064
authz := casbin.New(casbin.Config{
6165
ModelFilePath: "path/to/rbac_model.conf",
6266
PolicyAdapter: xormadapter.NewAdapter("mysql", "root:@tcp(127.0.0.1:3306)/"),
63-
Lookup: func(c *fiber.Ctx) string {
67+
Lookup: func(c fiber.Ctx) string {
6468
// fetch authenticated user subject
6569
},
6670
})
6771

6872
app.Post("/blog",
6973
authz.RequiresPermissions([]string{"blog:create"}, casbin.WithValidationRule(casbin.MatchAllRule)),
70-
func(c *fiber.Ctx) error {
74+
func(c fiber.Ctx) error {
7175
// your handler
7276
},
7377
)
7478

7579
app.Delete("/blog/:id",
7680
authz.RequiresPermissions([]string{"blog:create", "blog:delete"}, casbin.WithValidationRule(casbin.AtLeastOneRule)),
77-
func(c *fiber.Ctx) error {
81+
func(c fiber.Ctx) error {
7882
// your handler
7983
},
8084
)
@@ -89,8 +93,8 @@ func main() {
8993
package main
9094

9195
import (
92-
"github.com/gofiber/fiber/v2"
93-
"github.com/gofiber/contrib/casbin"
96+
"github.com/gofiber/fiber/v3"
97+
"github.com/gofiber/contrib/v3/casbin"
9498
_ "github.com/go-sql-driver/mysql"
9599
"github.com/casbin/xorm-adapter/v2"
96100
)
@@ -101,15 +105,15 @@ func main() {
101105
authz := casbin.New(casbin.Config{
102106
ModelFilePath: "path/to/rbac_model.conf",
103107
PolicyAdapter: xormadapter.NewAdapter("mysql", "root:@tcp(127.0.0.1:3306)/"),
104-
Lookup: func(c *fiber.Ctx) string {
108+
Lookup: func(c fiber.Ctx) string {
105109
// fetch authenticated user subject
106110
},
107111
})
108112

109113
// check permission with Method and Path
110114
app.Post("/blog",
111115
authz.RoutePermission(),
112-
func(c *fiber.Ctx) error {
116+
func(c fiber.Ctx) error {
113117
// your handler
114118
},
115119
)
@@ -124,8 +128,8 @@ func main() {
124128
package main
125129

126130
import (
127-
"github.com/gofiber/fiber/v2"
128-
"github.com/gofiber/contrib/casbin"
131+
"github.com/gofiber/fiber/v3"
132+
"github.com/gofiber/contrib/v3/casbin"
129133
_ "github.com/go-sql-driver/mysql"
130134
"github.com/casbin/xorm-adapter/v2"
131135
)
@@ -136,14 +140,14 @@ func main() {
136140
authz := casbin.New(casbin.Config{
137141
ModelFilePath: "path/to/rbac_model.conf",
138142
PolicyAdapter: xormadapter.NewAdapter("mysql", "root:@tcp(127.0.0.1:3306)/"),
139-
Lookup: func(c *fiber.Ctx) string {
143+
Lookup: func(c fiber.Ctx) string {
140144
// fetch authenticated user subject
141145
},
142146
})
143147

144148
app.Put("/blog/:id",
145149
authz.RequiresRoles([]string{"admin"}),
146-
func(c *fiber.Ctx) error {
150+
func(c fiber.Ctx) error {
147151
// your handler
148152
},
149153
)

0 commit comments

Comments
 (0)