Skip to content

Commit

Permalink
v2 update
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneWerner87 committed Jun 30, 2024
1 parent fca57aa commit 03394fd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/core/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func main() {

Returns an instance of a single route, which you can then use to handle HTTP verbs with optional middleware.

Similar to [`Express`](https://expressjs.com/de/api.html#app.route).
Similar to [`express`](https://expressjs.com/de/api.html#app.route).

```go title="Signature"
func (app *App) Route(path string) Register
Expand Down
13 changes: 8 additions & 5 deletions versioned_docs/version-v2.x/api/ctx.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,28 +900,31 @@ app.Get("/", func(c *fiber.Ctx) error {
## Locals
A method that stores variables scoped to the request and, therefore, are available only to the routes that match the request.
A method that stores variables scoped to the request and, therefore, are available only to the routes that match the request. The stored variables are removed after the request is handled. If any of the stored data implements the `io.Closer` interface, its `Close` method will be called before it's removed.
:::tip
This is useful if you want to pass some **specific** data to the next middleware.
This is useful if you want to pass some **specific** data to the next middleware. Remember to perform type assertions when retrieving the data to ensure it is of the expected type. You can also use a non-exported type as a key to avoid collisions.
:::
```go title="Signature"
func (c *Ctx) Locals(key interface{}, value ...interface{}) interface{}
```
```go title="Example"
type keyType struct{}
var userKey keyType

app.Use(func(c *fiber.Ctx) error {
c.Locals("user", "admin")
c.Locals(userKey, "admin") // Stores the string "admin" under a non-exported type key
return c.Next()
})

app.Get("/admin", func(c *fiber.Ctx) error {
if c.Locals("user") == "admin" {
user, ok := c.Locals(userKey).(string) // Retrieves the data stored under the key and performs a type assertion
if ok && user == "admin" {
return c.Status(fiber.StatusOK).SendString("Welcome, admin!")
}
return c.SendStatus(fiber.StatusForbidden)

})
```
Expand Down
3 changes: 1 addition & 2 deletions versioned_docs/version-v2.x/api/middleware/logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ app.Use(logger.New(logger.Config{
| Next | `func(*fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` |
| Done | `func(*fiber.Ctx, []byte)` | Done is a function that is called after the log string for a request is written to Output, and pass the log string as parameter. | `nil` |
| CustomTags | `map[string]LogFunc` | tagFunctions defines the custom tag action. | `map[string]LogFunc` |
| Format | `string` | Format defines the logging tags. | `${time} \| ${status} \| ${latency} \| ${ip} \| ${method} \| ${path} \| ${error}\n` |
| TimeFormat | `string` | TimeFormat defines the time format for log timestamps. | `15:04:05` |
| Format | `string` | Format defines the logging tags. | `${time} \| ${status} \| ${latency} \| ${ip} \| ${method} \| ${path} \| ${error}\n` || TimeFormat | `string` | TimeFormat defines the time format for log timestamps. | `15:04:05` |
| TimeZone | `string` | TimeZone can be specified, such as "UTC" and "America/New_York" and "Asia/Chongqing", etc | `"Local"` |
| TimeInterval | `time.Duration` | TimeInterval is the delay before the timestamp is updated. | `500 * time.Millisecond` |
| Output | `io.Writer` | Output is a writer where logs are written. | `os.Stdout` |
Expand Down
2 changes: 1 addition & 1 deletion versioned_docs/version-v2.x/guide/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Constraints aren't validation for parameters. If constraints aren't valid for a

| Constraint | Example | Example matches |
| ----------------- | ------------------------------------ | ------------------------------------------------------------------------------------------- |
| int | `:id<int\>` | 123456789, -123456789 |
| int | `:id<int\>` | 123456789, -123456789 |
| bool | `:active<bool\>` | true,false |
| guid | `:id<guid\>` | CD2C1638-1638-72D5-1638-DEADBEEF1638 |
| float | `:weight<float\>` | 1.234, -1,001.01e8 |
Expand Down

0 comments on commit 03394fd

Please sign in to comment.