-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Gin compat #260
base: main
Are you sure you want to change the base?
Gin compat #260
Conversation
b4d06b5
to
778d992
Compare
542238f
to
0b9a903
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fuegogin is a strange name either for folder name and package
What about using one of these?
extra/adapter/gin.go
extra/gin/adapter.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gin
as a Fuego Extra package name will obviously collide with gin
the router.
It still needs to reference gin. I don't have good ideas. I'll ask ChatGPT 😆
|
||
type ContextNoBody = ContextWithBody[any] | ||
|
||
// Body implements fuego.Ctx. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use godoc
// Body implements fuego.Ctx. | |
// Body implements [fuego.Ctx]. |
But also, this could be better
// Body implements fuego.Ctx. | |
// Body satisfies [fuego.Ctx]. |
Body itself doesn't implements the interface, it helps to comply and satisfy it
|
||
// Cookie implements fuego.Ctx. | ||
func (c *ContextWithBody[B]) Cookie(name string) (*http.Cookie, error) { | ||
panic("unimplemented") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define a sentinel error, you will be able to catch in tests with a type assertion, then check its value with an errors.Is
// Cookie implements fuego.Ctx. | |
func (c *ContextWithBody[B]) Cookie(name string) (*http.Cookie, error) { | |
panic("unimplemented") | |
} | |
var ErrUnimplemented = errors.New("unimplemented") | |
// Cookie implements fuego.Ctx. | |
func (c *ContextWithBody[B]) Cookie(name string) (*http.Cookie, error) { | |
panic(ErrUnimplemented) | |
} |
mux.go
Outdated
description := "#### Controller: \n\n`" + | ||
handler + "`" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be more readable I think
description := "#### Controller: \n\n`" + | |
handler + "`" | |
description := fmt.Sprintf ("#### Controller: \n\n`%s`", handler) | |
description += "\n\n#### Middlewares:\n" | ||
|
||
for i, fn := range middlewares { | ||
description += "\n- `" + FuncName(fn) + "`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same logic
openapi.go
Outdated
} | ||
|
||
if route.Operation.OperationID == "" { | ||
route.Operation.OperationID = route.Method + "_" + strings.ReplaceAll(strings.ReplaceAll(route.Path, "{", ":"), "}", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a func to clean operation ID, this code is duplicated
option.go
Outdated
// Description appends a description to the route. | ||
// By default, the description is set by Fuego with some info, | ||
// like the controller function name and the package name. | ||
func OptionOverrideDescription(description string) func(*BaseRoute) { | ||
return func(r *BaseRoute) { | ||
r.OverrideDescription = true | ||
r.Operation.Description = description | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't I provide a feedback for this?
About the fact the code is a copy pasta, and should be
// OptionOverrideDescription overrides the default description set by Fuego.
// By default, the description is set by Fuego with some info,
// like the controller function name and the package name.
Thanks for the memes @ccoVeille 😆 |
Co-authored-by: ccoVeille <[email protected]>
Co-authored-by: ccoVeille <[email protected]>
Fixes #241 : it works!!! 🎉
🚧 Ultra-WIP as it is not ready for production.
Enables the way for Echo & other frameworks.
The (challengeable) goal here is not to support both frameworks but to allow smooth transition towards stdlib.