Skip to content

Commit

Permalink
fix doc examples for generic function
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneWerner87 committed Jan 6, 2025
1 parent ac82b0c commit a95ffd8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions docs/guide/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func GetReqHeader[V any](c Ctx, key string, defaultValue ...V) V
```go title="Example"
app.Get("/search", func(c fiber.Ctx) error {
// curl -X GET http://example.com/search -H "X-Request-ID: 12345" -H "X-Request-Name: John"
GetReqHeader[int](c, "X-Request-ID") // => returns 12345 as integer.
GetReqHeader[string](c, "X-Request-Name") // => returns "John" as string.
GetReqHeader[string](c, "unknownParam", "default") // => returns "default" as string.
fiber.GetReqHeader[int](c, "X-Request-ID") // => returns 12345 as integer.
fiber.GetReqHeader[string](c, "X-Request-Name") // => returns "John" as string.
fiber.GetReqHeader[string](c, "unknownParam", "default") // => returns "default" as string.
// ...
})
```
Expand Down Expand Up @@ -97,8 +97,8 @@ func Params[V any](c Ctx, key string, defaultValue ...V) V
```go title="Example"
app.Get("/user/:user/:id", func(c fiber.Ctx) error {
// http://example.com/user/john/25
Params[int](c, "id") // => returns 25 as integer.
Params[int](c, "unknownParam", 99) // => returns the default 99 as integer.
fiber.Params[int](c, "id") // => returns 25 as integer.
fiber.Params[int](c, "unknownParam", 99) // => returns the default 99 as integer.
// ...
return c.SendString("Hello, " + fiber.Params[string](c, "user"))
})
Expand All @@ -116,9 +116,9 @@ func Query[V any](c Ctx, key string, defaultValue ...V) V
```go title="Example"
app.Get("/search", func(c fiber.Ctx) error {
// http://example.com/search?name=john&age=25
Query[string](c, "name") // => returns "john"
Query[int](c, "age") // => returns 25 as integer.
Query[string](c, "unknownParam", "default") // => returns "default" as string.
fiber.Query[string](c, "name") // => returns "john"
fiber.Query[int](c, "age") // => returns 25 as integer.
fiber.Query[string](c, "unknownParam", "default") // => returns "default" as string.
// ...
})
```
8 changes: 4 additions & 4 deletions docs/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func main() {
app := fiber.New()

app.Get("/convert", func(c fiber.Ctx) error {
value, err := Convert[string](c.Query("value"), strconv.Atoi, 0)
value, err := fiber.Convert[string](c.Query("value"), strconv.Atoi, 0)
if err != nil {
return c.Status(fiber.StatusBadRequest).SendString(err.Error())
}
Expand Down Expand Up @@ -575,7 +575,7 @@ func main() {
app := fiber.New()

app.Get("/params/:id", func(c fiber.Ctx) error {
id := Params[int](c, "id", 0)
id := fiber.Params[int](c, "id", 0)
return c.JSON(id)
})

Expand Down Expand Up @@ -607,7 +607,7 @@ func main() {
app := fiber.New()

app.Get("/query", func(c fiber.Ctx) error {
age := Query[int](c, "age", 0)
age := fiber.Query[int](c, "age", 0)
return c.JSON(age)
})

Expand Down Expand Up @@ -640,7 +640,7 @@ func main() {
app := fiber.New()

app.Get("/header", func(c fiber.Ctx) error {
userAgent := GetReqHeader[string](c, "User-Agent", "Unknown")
userAgent := fiber.GetReqHeader[string](c, "User-Agent", "Unknown")
return c.JSON(userAgent)
})

Expand Down

0 comments on commit a95ffd8

Please sign in to comment.