-
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
ShouldBind counterparts for Bind methods #1047
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1047 +/- ##
==========================================
+ Coverage 96.67% 96.68% +0.01%
==========================================
Files 16 16
Lines 1714 1721 +7
==========================================
+ Hits 1657 1664 +7
Misses 49 49
Partials 8 8
Continue to review full report at Codecov.
|
@appleboy Shall I update the readme to use |
@sudo-suhas OK, Welcome |
c919aef
to
4bbff4f
Compare
@sudo-suhas, @appleboy: thanks for introducing the |
af675da
to
a20a15a
Compare
Rebased. Could we please move forward with this? I can do any changes if needed. |
@javierprovecho Please help to review this PR. Waiting for your feedbacks. |
b0d5e9d
to
e04297d
Compare
maybe rename/refactor your methods |
As I mentioned earlier:
Additionally, this PR also adds relevant documentation to explain and clarify the differences between |
I'm against backward compatibility, there are exist previous version of framework, this can be added in 1.3 |
I think that is for the repo maintainers to decide. I am more than willing to do the requested changes. |
1f8f1fc
to
397284e
Compare
bf9d8b8
to
f7ccbeb
Compare
f7ccbeb
to
5740ece
Compare
ping @javierprovecho @appleboy |
Add section for bind methods types, explain difference in behavior. Switch all `c.Bind` examples to use `c.ShouldBind`.
5740ece
to
e8d927a
Compare
Hey @javierprovecho, @appleboy, it has been over 2 months since I first initiated this pull request. Is there anything at all, that I can do, so that we move forward with this? Any communication, even if it is to reject this pull requests, would be welcome. While I am aware that you would be working on this in your free time, IMHO, lack of communication can really make it harder for contributors to make repeat pull requests. |
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.
@sudo-suhas I agree with you, it is my fault for leaving somehow unattended the repo. I'm now most convinced that it is responsibility of the developer to lock version/commit of the framework. The project have been for more than two minor versions with an indication in the readme about how to use vendor. I apologize about the delay.
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.
@sudo-suhas thanks for your pr!
@javierprovecho Thank you for accepting the PR 😄. Could you explain the context for your comment:
|
@sudo-suhas I've been holding many pr that break stability on api level or behavior level (ex: #1061) because when gin originally was published, there was no vendor tool popular enough for locking into a specific version.
As said, https://github.com/gin-gonic/gin#use-a-vendor-tool-like-govendor it has been present for some months since now and vendoring is a common practice in the golang community since ~ 1.6 EDIT: of course, this doesn't mean the project goes crazy now, just a bit (lot) less conservative 😉 with its corresponding warnings in the changelog and common sense of course |
Yes, I also use vendoring. I also made a PR for |
@sudo-suhas about that, another concern I had with your pr was that the API would not scale properly in the future with long named funcs, but that will have an easier solution that I'm planning EDIT: i'll need to check |
Issue Description
Currently, the functions
ctx.Bind
,ctx.BindJSON
,ctx.BindQuery
all usectx.MustBindWith
.In my opinion, the current implementation of
ctx.MustBindWith
has the following drawbacks. Note that this has been discussed before and I am including it here to avoid needing to crawl multiple issues, threads:http.StatusUnprocessableEntity
)Bind
as discussed in Bind JSON and Query? #811. Developer might want to bind query params and JSON body separately.Content-type
headerContent-type
astext/plain
ctx.JSON
nor manually trying to set the content type header help. Instead we see this warning:Proposal
For backward compatibility, we cannot change the behavior of existing bind methods. So this PR adds
ShouldBind
counterparts -ctx.ShouldBind
,ctx.ShouldBindJSON
,ctx.ShouldBindQuery
.Note that I have not yet updated the readme file and will do so depending on the outcome of the discussion here. I suggest that we switch over all examples on readme to use theShould
equivalents.All examples on readme have been updated to use
ShouldBind
methods. Also added section explaining difference betweenBind
andShouldBind
methods.For example, this isn't going to work if there is a bind error:
I am new to Go 🙇 . I have pretty much duplicated the existing tests for bind methods with
Should
equivalents. Please let me know if anything needs to be changed.Related issues - #629, #633, #662, #782, #811
Related PR - #636, #661
Closes #840