-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync docs for release https://github.com/gofiber/contrib/releases/tag…
- Loading branch information
1 parent
1dc234c
commit 7b80365
Showing
19 changed files
with
2,367 additions
and
0 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,36 @@ | ||
--- | ||
title: 👋 Welcome | ||
sidebar_position: 1 | ||
--- | ||
|
||
<div align="center"> | ||
<img height="125" alt="Fiber" src="https://raw.githubusercontent.com/gofiber/contrib/master/.github/logo-dark.svg#gh-dark-mode-only" /> | ||
<img height="125" alt="Fiber" src="https://raw.githubusercontent.com/gofiber/contrib/master/.github/logo.svg#gh-light-mode-only" /> | ||
<br /> | ||
|
||
[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) | ||
![Test](https://github.com/gofiber/contrib/workflows/Tests/badge.svg) | ||
![Security](https://github.com/gofiber/contrib/workflows/Security/badge.svg) | ||
![Linter](https://github.com/gofiber/contrib/workflows/Linter/badge.svg) | ||
|
||
Repository for third party middlewares with dependencies. | ||
|
||
</div> | ||
|
||
## 📑 Middleware Implementations | ||
|
||
* [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" /> </a> | ||
* [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" /> </a> | ||
* [Fiberi18n](./fiberi18n/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+fiberi18n%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-fiberi18n.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a> | ||
* [Fibersentry](./fibersentry/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+fibersentry%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-fibersentry.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a> | ||
* [Fiberzap](./fiberzap/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+fiberzap%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-fiberzap.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a> | ||
* [Fiberzerolog](./fiberzerolog/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+fiberzerolog%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-fiberzerolog.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a> | ||
* [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" /> </a> | ||
* [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" /> </a> | ||
* [NewRelic](./fibernewrelic/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+fibernewrelic%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-fibernewrelic.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a> | ||
* [Open Policy Agent](./opafiber/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+opafiber%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-opafiber.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a> | ||
* [Otelfiber (OpenTelemetry)](./otelfiber/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+otelfiber%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-otelfiber.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a> | ||
* [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" /> </a> | ||
* [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" /> </a> | ||
* [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" /> </a> | ||
* [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" /> </a> |
155 changes: 155 additions & 0 deletions
155
contrib_versioned_docs/version-socketio_v1.x.x/casbin/README.md
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,155 @@ | ||
--- | ||
id: casbin | ||
--- | ||
|
||
# Casbin | ||
|
||
![Release](https://img.shields.io/github/v/tag/gofiber/contrib?filter=casbin*) | ||
[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) | ||
![Test](https://github.com/gofiber/contrib/workflows/Tests/badge.svg) | ||
![Security](https://github.com/gofiber/contrib/workflows/Security/badge.svg) | ||
![Linter](https://github.com/gofiber/contrib/workflows/Linter/badge.svg) | ||
|
||
Casbin middleware for Fiber. | ||
|
||
**Note: Requires Go 1.18 and above** | ||
|
||
## Install | ||
``` | ||
go get -u github.com/gofiber/fiber/v2 | ||
go get -u github.com/gofiber/contrib/casbin | ||
``` | ||
choose an adapter from [here](https://casbin.org/docs/en/adapters) | ||
``` | ||
go get -u github.com/casbin/xorm-adapter | ||
``` | ||
|
||
## Signature | ||
```go | ||
casbin.New(config ...casbin.Config) *casbin.Middleware | ||
``` | ||
|
||
## Config | ||
|
||
| Property | Type | Description | Default | | ||
|:--------------|:--------------------------|:-----------------------------------------|:--------------------------------------------------------------------| | ||
| ModelFilePath | `string` | Model file path | `"./model.conf"` | | ||
| PolicyAdapter | `persist.Adapter` | Database adapter for policies | `./policy.csv` | | ||
| Enforcer | `*casbin.Enforcer` | Custom casbin enforcer | `Middleware generated enforcer using ModelFilePath & PolicyAdapter` | | ||
| Lookup | `func(*fiber.Ctx) string` | Look up for current subject | `""` | | ||
| Unauthorized | `func(*fiber.Ctx) error` | Response body for unauthorized responses | `Unauthorized` | | ||
| Forbidden | `func(*fiber.Ctx) error` | Response body for forbidden responses | `Forbidden` | | ||
|
||
### Examples | ||
- [Gorm Adapter](https://github.com/svcg/-fiber_casbin_demo) | ||
- [File Adapter](https://github.com/gofiber/contrib/casbin/tree/master/example) | ||
|
||
## CustomPermission | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/contrib/casbin" | ||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/casbin/xorm-adapter/v2" | ||
) | ||
|
||
func main() { | ||
app := fiber.New() | ||
|
||
authz := casbin.New(casbin.Config{ | ||
ModelFilePath: "path/to/rbac_model.conf", | ||
PolicyAdapter: xormadapter.NewAdapter("mysql", "root:@tcp(127.0.0.1:3306)/"), | ||
Lookup: func(c *fiber.Ctx) string { | ||
// fetch authenticated user subject | ||
}, | ||
}) | ||
|
||
app.Post("/blog", | ||
authz.RequiresPermissions([]string{"blog:create"}, casbin.WithValidationRule(casbin.MatchAllRule)), | ||
func(c *fiber.Ctx) error { | ||
// your handler | ||
}, | ||
) | ||
|
||
app.Delete("/blog/:id", | ||
authz.RequiresPermissions([]string{"blog:create", "blog:delete"}, casbin.WithValidationRule(casbin.AtLeastOneRule)), | ||
func(c *fiber.Ctx) error { | ||
// your handler | ||
}, | ||
) | ||
|
||
app.Listen(":8080") | ||
} | ||
``` | ||
|
||
## RoutePermission | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/contrib/casbin" | ||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/casbin/xorm-adapter/v2" | ||
) | ||
|
||
func main() { | ||
app := fiber.New() | ||
|
||
authz := casbin.New(casbin.Config{ | ||
ModelFilePath: "path/to/rbac_model.conf", | ||
PolicyAdapter: xormadapter.NewAdapter("mysql", "root:@tcp(127.0.0.1:3306)/"), | ||
Lookup: func(c *fiber.Ctx) string { | ||
// fetch authenticated user subject | ||
}, | ||
}) | ||
|
||
// check permission with Method and Path | ||
app.Post("/blog", | ||
authz.RoutePermission(), | ||
func(c *fiber.Ctx) error { | ||
// your handler | ||
}, | ||
) | ||
|
||
app.Listen(":8080") | ||
} | ||
``` | ||
|
||
## RoleAuthorization | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/contrib/casbin" | ||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/casbin/xorm-adapter/v2" | ||
) | ||
|
||
func main() { | ||
app := fiber.New() | ||
|
||
authz := casbin.New(casbin.Config{ | ||
ModelFilePath: "path/to/rbac_model.conf", | ||
PolicyAdapter: xormadapter.NewAdapter("mysql", "root:@tcp(127.0.0.1:3306)/"), | ||
Lookup: func(c *fiber.Ctx) string { | ||
// fetch authenticated user subject | ||
}, | ||
}) | ||
|
||
app.Put("/blog/:id", | ||
authz.RequiresRoles([]string{"admin"}), | ||
func(c *fiber.Ctx) error { | ||
// your handler | ||
}, | ||
) | ||
|
||
app.Listen(":8080") | ||
} | ||
``` |
59 changes: 59 additions & 0 deletions
59
contrib_versioned_docs/version-socketio_v1.x.x/fgprof/README.md
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,59 @@ | ||
--- | ||
id: fgprof | ||
--- | ||
|
||
# Fgprof | ||
|
||
![Release](https://img.shields.io/github/v/tag/gofiber/contrib?filter=fgprof*) | ||
[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) | ||
![Test](https://github.com/gofiber/contrib/workflows/Tests/badge.svg) | ||
![Security](https://github.com/gofiber/contrib/workflows/Security/badge.svg) | ||
![Linter](https://github.com/gofiber/contrib/workflows/Linter/badge.svg) | ||
|
||
[fgprof](https://github.com/felixge/fgprof) support for Fiber. | ||
|
||
**Note: Requires Go 1.19 and above** | ||
|
||
## Install | ||
|
||
This middleware supports Fiber v2. | ||
|
||
Using fgprof to profiling your Fiber app. | ||
|
||
``` | ||
go get -u github.com/gofiber/fiber/v2 | ||
go get -u github.com/gofiber/contrib/fgprof | ||
``` | ||
|
||
## Config | ||
|
||
| Property | Type | Description | Default | | ||
|----------|---------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|---------| | ||
| Next | `func(c *fiber.Ctx) bool` | A function to skip this middleware when returned `true`. | `nil` | | ||
| Prefix | `string`. | Prefix defines a URL prefix added before "/debug/fgprof". Note that it should start with (but not end with) a slash. Example: "/federated-fiber" | `""` | | ||
|
||
## Example | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/gofiber/contrib/fgprof" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func main() { | ||
app := fiber.New() | ||
app.Use(fgprof.New()) | ||
app.Get("/", func(c *fiber.Ctx) error { | ||
return c.SendString("OK") | ||
}) | ||
log.Fatal(app.Listen(":3000")) | ||
} | ||
``` | ||
|
||
```bash | ||
go tool pprof -http=:8080 http://localhost:3000/debug/fgprof | ||
``` |
88 changes: 88 additions & 0 deletions
88
contrib_versioned_docs/version-socketio_v1.x.x/fiberi18n/README.md
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,88 @@ | ||
--- | ||
id: fiberi18n | ||
--- | ||
|
||
# Fiberi18n | ||
|
||
![Release](https://img.shields.io/github/v/tag/gofiber/contrib?filter=fiberi18n*) | ||
[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) | ||
![Test](https://github.com/gofiber/contrib/workflows/Tests/badge.svg) | ||
![Security](https://github.com/gofiber/contrib/workflows/Security/badge.svg) | ||
![Linter](https://github.com/gofiber/contrib/workflows/Linter/badge.svg) | ||
|
||
[go-i18n](https://github.com/nicksnyder/go-i18n) support for Fiber. | ||
|
||
**Note: Requires Go 1.18 and above** | ||
|
||
## Install | ||
|
||
This middleware supports Fiber v2. | ||
|
||
``` | ||
go get -u github.com/gofiber/fiber/v2 | ||
go get -u github.com/gofiber/contrib/fiberi18n/v2 | ||
``` | ||
|
||
## Signature | ||
|
||
| Name | Signature | Description | | ||
|--------------|----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------| | ||
| New | `New(config ...*fiberi18n.Config) fiber.Handler` | Create a new fiberi18n middleware handler | | ||
| Localize | `Localize(ctx *fiber.Ctx, params interface{}) (string, error)` | Localize returns a localized message. param is one of these type: messageID, *i18n.LocalizeConfig | | ||
| MustLocalize | `MustLocalize(ctx *fiber.Ctx, params interface{}) string` | MustLocalize is similar to Localize, except it panics if an error happens. param is one of these type: messageID, *i18n.LocalizeConfig | | ||
|
||
## Config | ||
|
||
| Property | Type | Description | Default | | ||
|------------------|---------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------| | ||
| Next | `func(c *fiber.Ctx) bool` | A function to skip this middleware when returned `true`. | `nil` | | ||
| RootPath | `string` | The i18n template folder path. | `"./example/localize"` | | ||
| AcceptLanguages | `[]language.Tag` | A collection of languages that can be processed. | `[]language.Tag{language.Chinese, language.English}` | | ||
| FormatBundleFile | `string` | The type of the template file. | `"yaml"` | | ||
| DefaultLanguage | `language.Tag` | The default returned language type. | `language.English` | | ||
| Loader | `Loader` | The implementation of the Loader interface, which defines how to read the file. We provide both os.ReadFile and embed.FS.ReadFile. | `LoaderFunc(os.ReadFile)` | | ||
| UnmarshalFunc | `i18n.UnmarshalFunc` | The function used for decoding template files. | `yaml.Unmarshal` | | ||
| LangHandler | `func(ctx *fiber.Ctx, defaultLang string) string` | Used to get the kind of language handled by *fiber.Ctx and defaultLang. | Retrieved from the request header `Accept-Language` or query parameter `lang`. | | ||
|
||
## Example | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/gofiber/contrib/fiberi18n/v2" | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/nicksnyder/go-i18n/v2/i18n" | ||
"golang.org/x/text/language" | ||
) | ||
|
||
func main() { | ||
app := fiber.New() | ||
app.Use( | ||
fiberi18n.New(&fiberi18n.Config{ | ||
RootPath: "./example/localize", | ||
AcceptLanguages: []language.Tag{language.Chinese, language.English}, | ||
DefaultLanguage: language.Chinese, | ||
}), | ||
) | ||
app.Get("/", func(c *fiber.Ctx) error { | ||
localize, err := fiberi18n.Localize(c, "welcome") | ||
if err != nil { | ||
return c.Status(fiber.StatusInternalServerError).SendString(err.Error()) | ||
} | ||
return c.SendString(localize) | ||
}) | ||
app.Get("/:name", func(ctx *fiber.Ctx) error { | ||
return ctx.SendString(fiberi18n.MustLocalize(ctx, &i18n.LocalizeConfig{ | ||
MessageID: "welcomeWithName", | ||
TemplateData: map[string]string{ | ||
"name": ctx.Params("name"), | ||
}, | ||
})) | ||
}) | ||
log.Fatal(app.Listen(":3000")) | ||
} | ||
``` | ||
|
Oops, something went wrong.