-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Feature Description
Some APIs like ctx.QueryBool or ctx.QueryFloat convert given variables. Why don't add APIs that let users convert the needed variable types?
For example, Query convertor API can be implemented like this (Since we can't use generics in methods):
func QueryFunc[T any](c *Ctx, key string, convertor func(string)(T, error), defaultValue ...T) (T, error)Usage:
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
"log"
)
func main() {
app := fiber.New()
// [GET] /?id=01827964-1320-47b4-b2fa-c67fa9c39bed
app.Get("/", func(c *fiber.Ctx) error {
id, err := fiber.QueryFunc(c, "id", uuid.Parse)
if err != nil {
log.Fatal(err)
}
// some functionality
})
app.Listen(":3000")
}We can implement other APIs like ctx.Params and ctx.Get functions.
Additional Context (optional)
No response
Code Snippet (optional)
No response
Checklist:
- I agree to follow Fiber's Code of Conduct.
- I have checked for existing issues that describe my suggestion prior to opening this one.
- I understand that improperly formatted feature requests may be closed without explanation.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Type
Projects
Status
Done