Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📚 Docs: Fix typos, and make middleware documentation more consistent #2408

Merged
merged 2 commits into from Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/bug-report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ body:
value: |
### Notice
**This repository is not related to external or third-part Fiber modules. If you have a problem with them, open an issue under their repos. If you think the problem is related to Fiber, open the issue here.**
- Dont't forget you can ask your questions on our [Discord server](https://gofiber.io/discord).
- If you think Fiber doesn't have a nice feature that you think, open the issue with **✏️ Feature Request** template.
- Don't forget you can ask your questions in our [Discord server](https://gofiber.io/discord).
- If you have a suggestion for a Fiber feature you would like to see, open the issue with the **✏️ Feature Request** template.
- Write your issue with clear and understandable English.
- type: textarea
id: description
attributes:
label: "Bug Description"
description: "A clear and detailed description of what the bug is."
placeholder: "Explain your problem as clear and detailed."
placeholder: "Explain your problem clearly and in detail."
validations:
required: true
- type: textarea
Expand All @@ -39,7 +39,7 @@ body:
id: expected-behavior
attributes:
label: Expected Behavior
description: "A clear and detailed description of what you think should happens."
description: "A clear and detailed description of what you think should happen."
placeholder: "Tell us what Fiber should normally do."
validations:
required: true
Expand All @@ -56,7 +56,7 @@ body:
attributes:
label: "Code Snippet (optional)"
description: "For some issues, we need to know some parts of your code."
placeholder: "Share a code you think related to the issue."
placeholder: "Share a code snippet that you think is related to the issue."
render: go
value: |
package main
Expand Down
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/feature-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ body:
attributes:
value: |
### Notice
- Dont't forget you can ask your questions on our [Discord server](https://gofiber.io/discord).
- If you think this is just a bug, open the issue with **☢️ Bug Report** template.
- Don't forget you can ask your questions in our [Discord server](https://gofiber.io/discord).
- If you think this is just a bug, open the issue with the **☢️ Bug Report** template.
- Write your issue with clear and understandable English.
- type: textarea
id: description
attributes:
label: "Feature Description"
description: "A clear and detailed description of the feature we need to do."
placeholder: "Explain your feature as clear and detailed."
description: "A clear and detailed description of the feature you would like to see added."
placeholder: "Explain your feature clearly, and in detail."
validations:
required: true
- type: textarea
Expand All @@ -31,7 +31,7 @@ body:
attributes:
label: "Code Snippet (optional)"
description: "Code snippet may be really helpful to describe some features."
placeholder: "Share a code to explain the feature better."
placeholder: "Share a code snippet to explain the feature better."
render: go
value: |
package main
Expand Down
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/question.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ body:
attributes:
value: |
### Notice
- Dont't forget you can ask your questions on our [Discord server](https://gofiber.io/discord).
- If you think this is just a bug, open the issue with **☢️ Bug Report** template.
- If you think Fiber doesn't have a nice feature that you think, open the issue with **✏️ Feature Request** template.
- Don't forget you can ask your questions in our [Discord server](https://gofiber.io/discord).
- If you think this is just a bug, open the issue with the **☢️ Bug Report** template.
- If you have a suggestion for a Fiber feature you would like to see, open the issue with the **✏️ Feature Request** template.
- Write your issue with clear and understandable English.
- type: textarea
id: description
attributes:
label: "Question Description"
description: "A clear and detailed description of the question."
placeholder: "Explain your question as clear and detailed."
placeholder: "Explain your question clearly, and in detail."
validations:
required: true
- type: textarea
id: snippet
attributes:
label: "Code Snippet (optional)"
description: "Code snippet may be really helpful to describe some features."
placeholder: "Share a code to explain the feature better."
placeholder: "Share a code snippet to explain the feature better."
render: go
value: |
package main
Expand Down
1 change: 0 additions & 1 deletion docs/api/middleware/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ type Config struct {
## Default Config

```go
// ConfigDefault is the default config
var ConfigDefault = Config{
Next: nil,
Expiration: 1 * time.Minute,
Expand Down
6 changes: 3 additions & 3 deletions docs/api/middleware/compress.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
After you initiate your Fiber app, you can use the following possibilities:

```go
// Default middleware config
// Initialize default config
app.Use(compress.New())

// Provide a custom compression level
// Or extend your config for customization
app.Use(compress.New(compress.Config{
Level: compress.LevelBestSpeed, // 1
}))
Expand All @@ -52,7 +52,7 @@ type Config struct {
// Optional. Default: nil
Next func(c *fiber.Ctx) bool

// CompressLevel determines the compression algoritm
// Level determines the compression algoritm
//
// Optional. Default: LevelDefault
// LevelDisabled: -1
Expand Down
23 changes: 15 additions & 8 deletions docs/api/middleware/cors.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
After you initiate your Fiber app, you can use the following possibilities:

```go
// Default config
// Initialize default config
app.Use(cors.New())

// Or extend your config for customization
Expand Down Expand Up @@ -88,12 +88,19 @@ type Config struct {

```go
var ConfigDefault = Config{
Next: nil,
AllowOrigins: "*",
AllowMethods: "GET,POST,HEAD,PUT,DELETE,PATCH",
AllowHeaders: "",
AllowCredentials: false,
ExposeHeaders: "",
MaxAge: 0,
Next: nil,
AllowOrigins: "*",
AllowMethods: strings.Join([]string{
fiber.MethodGet,
fiber.MethodPost,
fiber.MethodHead,
fiber.MethodPut,
fiber.MethodDelete,
fiber.MethodPatch,
}, ","),
AllowHeaders: "",
AllowCredentials: false,
ExposeHeaders: "",
MaxAge: 0,
}
```
28 changes: 19 additions & 9 deletions docs/api/middleware/csrf.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ CSRF Tokens are generated on GET requests. You can retrieve the CSRF token with
When no `csrf_` cookie is set, or the token has expired, a new token will be generated and `csrf_` cookie set.

:::note

This middleware uses our [Storage](https:/gofiber/storage) package to support various databases through a single interface. The default configuration for this middleware saves data to memory, see the examples below for other databases._

This middleware uses our [Storage](https:/gofiber/storage) package to support various databases through a single interface. The default configuration for this middleware saves data to memory, see the examples below for other databases.
:::

## Signatures
Expand Down Expand Up @@ -49,7 +47,9 @@ app.Use(csrf.New(csrf.Config{
}))
```

Note: KeyLookup will be ignored if Extractor is explicitly set.
:::note
KeyLookup will be ignored if Extractor is explicitly set.
:::

## Config

Expand Down Expand Up @@ -137,14 +137,24 @@ type Config struct {

```go
var ConfigDefault = Config{
KeyLookup: "header:X-Csrf-Token",
CookieName: "csrf_",
CookieSameSite: "Lax",
Expiration: 1 * time.Hour,
KeyGenerator: utils.UUID,
KeyLookup: "header:" + HeaderName,
CookieName: "csrf_",
CookieSameSite: "Lax",
Expiration: 1 * time.Hour,
KeyGenerator: utils.UUID,
ErrorHandler: defaultErrorHandler,
Extractor: CsrfFromHeader(HeaderName),
}
```

## Constants

```go
const (
HeaderName = "X-Csrf-Token"
)
```

### Custom Storage/Database

You can use any storage from our [storage](https:/gofiber/storage/) package.
Expand Down
28 changes: 17 additions & 11 deletions docs/api/middleware/earlydata.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func New(config ...Config) fiber.Handler

## Examples

First import the middleware from Fiber,
Import the middleware package that is part of the Fiber web framework

```go
import (
Expand All @@ -33,26 +33,23 @@ import (
)
```

Then create a Fiber app with `app := fiber.New()`.

### Default Config
After you initiate your Fiber app, you can use the following possibilities:

```go
// Initialize default config
app.Use(earlydata.New())
```

### Custom Config

```go
// Or extend your config for customization
app.Use(earlydata.New(earlydata.Config{
Error: fiber.ErrTooEarly,
// ...
}))
```

### Config
## Config

```go
// Config defines the config for middleware.
type Config struct {
// Next defines a function to skip this middleware when returned true.
//
Expand All @@ -76,12 +73,12 @@ type Config struct {
}
```

### Default Config
## Default Config

```go
var ConfigDefault = Config{
IsEarlyData: func(c *fiber.Ctx) bool {
return c.Get("Early-Data") == "1"
return c.Get(DefaultHeaderName) == DefaultHeaderTrueValue
},

AllowEarlyData: func(c *fiber.Ctx) bool {
Expand All @@ -91,3 +88,12 @@ var ConfigDefault = Config{
Error: fiber.ErrTooEarly,
}
```

## Constants

```go
const (
DefaultHeaderName = "Early-Data"
DefaultHeaderTrueValue = "1"
)
```
19 changes: 12 additions & 7 deletions docs/api/middleware/encryptcookie.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import (
After you initiate your Fiber app, you can use the following possibilities:

```go
// Default middleware config
// Provide a minimal config
// `Key` must be a 32 character string. It's used to encrypt the values, so make sure it is random and keep it secret.
// You can run `openssl rand -base64 32` or call `encryptcookie.GenerateKey()` to create a random key for you.
// Make sure not to set `Key` to `encryptcookie.GenerateKey()` because that will create a new key every run.
app.Use(encryptcookie.New(encryptcookie.Config{
Key: "secret-thirty-2-character-string",
}))
Expand All @@ -52,6 +55,7 @@ app.Post("/", func(c *fiber.Ctx) error {
## Config

```go
// Config defines the config for middleware.
type Config struct {
// Next defines a function to skip this middleware when returned true.
//
Expand Down Expand Up @@ -84,12 +88,13 @@ type Config struct {
## Default Config

```go
// `Key` must be a 32 character string. It's used to encrpyt the values, so make sure it is random and keep it secret.
// You can run `openssl rand -base64 32` or call `encryptcookie.GenerateKey()` to create a random key for you.
// Make sure not to set `Key` to `encryptcookie.GenerateKey()` because that will create a new key every run.
app.Use(encryptcookie.New(encryptcookie.Config{
Key: "secret-thirty-2-character-string",
}))
var ConfigDefault = Config{
Next: nil,
Except: []string{"csrf_"},
Key: "",
Encryptor: EncryptCookie,
Decryptor: DecryptCookie,
}
```

## Usage of CSRF and Encryptcookie Middlewares with Custom Cookie Names
Expand Down
20 changes: 9 additions & 11 deletions docs/api/middleware/envvar.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func New(config ...Config) fiber.Handler

## Examples

First import the middleware from Fiber,
Import the middleware package that is part of the Fiber web framework

```go
import (
Expand All @@ -22,19 +22,13 @@ import (
)
```

Then create a Fiber app with `app := fiber.New()`.

**Note**: You need to provide a path to use envvar middleware.

### Default Config
After you initiate your Fiber app, you can use the following possibilities:

```go
// Initialize default config
app.Use("/expose/envvars", envvar.New())
```

### Custom Config

```go
// Or extend your config for customization
app.Use("/expose/envvars", envvar.New(
envvar.Config{
ExportVars: map[string]string{"testKey": "", "testDefaultKey": "testDefaultVal"},
Expand All @@ -43,7 +37,11 @@ app.Use("/expose/envvars", envvar.New(
)
```

### Response
:::note
You will need to provide a path to use the envvar middleware.
:::

## Response

Http response contract:
```
Expand Down
8 changes: 2 additions & 6 deletions docs/api/middleware/etag.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@ import (

After you initiate your Fiber app, you can use the following possibilities:

### Default Config

```go
// Initialize default config
app.Use(etag.New())

// Get / receives Etag: "13-1831710635" in response header
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
```

### Custom Config

```go
// Or extend your config for customization
app.Use(etag.New(etag.Config{
Weak: true,
}))
Expand Down
Loading