-
Notifications
You must be signed in to change notification settings - Fork 138
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
58ba223
commit c909637
Showing
16 changed files
with
1,866 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,34 @@ | ||
--- | ||
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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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%22Tests%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test.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-fiberzap_v2.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") | ||
} | ||
``` |
80 changes: 80 additions & 0 deletions
80
contrib_versioned_docs/version-fiberzap_v2.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,80 @@ | ||
--- | ||
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 | ||
``` | ||
|
||
## Signature | ||
|
||
``` | ||
fiberi18n.New(config ...*fiberi18n.Config) fiber.Handler | ||
``` | ||
|
||
## 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 ( | ||
"github.com/gofiber/contrib/fiberi18n" | ||
"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 { | ||
return c.SendString(fiberi18n.MustGetMessage("welcome")) | ||
}) | ||
app.Get("/:name", func(ctx *fiber.Ctx) error { | ||
return ctx.SendString(fiberi18n.MustGetMessage(&i18n.LocalizeConfig{ | ||
MessageID: "welcomeWithName", | ||
TemplateData: map[string]string{ | ||
"name": ctx.Params("name"), | ||
}, | ||
})) | ||
}) | ||
app.Listen("127.0.0.1:3000") | ||
} | ||
``` | ||
|
102 changes: 102 additions & 0 deletions
102
contrib_versioned_docs/version-fiberzap_v2.x.x/fibernewrelic/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,102 @@ | ||
--- | ||
id: fibernewrelic | ||
--- | ||
|
||
# Fibernewrelic | ||
|
||
![Release](https://img.shields.io/github/v/tag/gofiber/contrib?filter=fibernewrelic*) | ||
[![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) | ||
|
||
[NewRelic](https://github.com/newrelic/go-agent) support 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/fibernewrelic | ||
``` | ||
|
||
## Signature | ||
|
||
```go | ||
fibernewrelic.New(config fibernewrelic.Config) fiber.Handler | ||
``` | ||
|
||
## Config | ||
|
||
| Property | Type | Description | Default | | ||
|:------------------|:-----------------|:---------------------------------------|:---------------| | ||
| License | `string` | Required - New Relic License Key | `""` | | ||
| AppName | `string` | New Relic Application Name | `fiber-api` | | ||
| Enabled | `bool` | Enable/Disable New Relic | `false` | | ||
| ~~TransportType~~ | ~~`string`~~ | ~~Can be HTTP or HTTPS~~ (Deprecated) | ~~`"HTTP"`~~ | | ||
| Application | `Application` | Existing New Relic App | `nil` | | ||
| ErrorStatusCodeHandler | `func(c *fiber.Ctx, err error) int` | If you want to change newrelic status code, you can use it. | `DefaultErrorStatusCodeHandler` | | ||
|
||
## Usage | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/contrib/fibernewrelic" | ||
) | ||
|
||
func main() { | ||
app := fiber.New() | ||
|
||
app.Get("/", func(ctx *fiber.Ctx) error { | ||
return ctx.SendStatus(200) | ||
}) | ||
|
||
cfg := fibernewrelic.Config{ | ||
License: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | ||
AppName: "MyCustomApi", | ||
Enabled: true, | ||
} | ||
|
||
app.Use(fibernewrelic.New(cfg)) | ||
|
||
app.Listen(":8080") | ||
} | ||
``` | ||
|
||
## Usage with existing New Relic application | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/contrib/fibernewrelic" | ||
"github.com/newrelic/go-agent/v3/newrelic" | ||
) | ||
|
||
func main() { | ||
newrelicApp, err := newrelic.NewApplication( | ||
newrelic.ConfigAppName("MyCustomApi"), | ||
newrelic.ConfigLicense("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), | ||
newrelic.ConfigEnabled(true), | ||
) | ||
|
||
app := fiber.New() | ||
|
||
app.Get("/", func(ctx *fiber.Ctx) error { | ||
return ctx.SendStatus(200) | ||
}) | ||
|
||
cfg := fibernewrelic.Config{ | ||
Application: newrelicApp | ||
} | ||
|
||
app.Use(fibernewrelic.New(cfg)) | ||
|
||
app.Listen(":8080") | ||
} | ||
``` |
Oops, something went wrong.