-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🚀 v3 Request: fiber.Ctx type of interface #1824
Comments
I have a question about this, what stop users doing the same thing if package main
import (
"fmt"
"github.com/gofiber/fiber/v2"
)
type CustomCtx struct {
*fiber.Ctx
}
func (cc CustomCtx) Foo() {
fmt.Println("foo")
}
func (cc CustomCtx) Boo() {
fmt.Println("bar")
}
func main() {
app := fiber.New(fiber.Config{})
app.Get("/", func(c *fiber.Ctx) error {
cc := CustomCtx{c}
cc.Foo()
cc.Boo()
return cc.JSON("")
})
} |
Yes it works. However, interfaces give us more extendable and readability. I support using interface as Ctx type because of its. |
It doesn't have any difference with your example, did I miss something? Is there a more complex example? |
If context is an interface, we can use type casting: cc := c.(*CustomCtx) But usages like |
Check #1928 (comment) |
If fiber.Ctx will be interface , we can customize it.
Example
The text was updated successfully, but these errors were encountered: