-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Is Gin Context violating the golang context styleguide? #4040
Comments
As much as I want to upvote Strict compliance, but this is Break change. Unrealistic :p some case: |
@xr I think it would be better to keep this issue in open state as an improvement reminder for the next major version of the gin it's extremely disorienting that I must not use the gin.Context and need to use (*gin.Context).Request.Context() instead PS: PPS: |
@mgerasimchuk sure, i just reopen this issues, and fyi, cross posting the discussions in the style guideline repo: google/styleguide#850 |
Hey guys,
We're having some discussions regarding whether or not Gin
Context
violates the Go context style guide. I'd like to hear your thoughts on this.According to the Go style guide (reference: Go Style Guide on Custom Contexts), it clearly states:
However, in the case of Gin's
HandlerFunc
, it passes a custom*Context
type.Even though the Gin
Context
implements all the methods of thecontext.Context
interface,as shown here
We still need to interpret the Go style guide. There seem to be two possible views on this:
Gin's
Context
is acceptable: Since it implements thecontext.Context
interface, it can be considered valid, and thus doesn't violate the style guide. Similarly, we could create other types like this:Strict compliance: To adhere to the Go style guide strictly, we should always pass
context.Context
directly in function signatures. In this case, the design would need to change to separate theContext
from custom APIs. For example, the function signature could be:What do you guys think?
The text was updated successfully, but these errors were encountered: