-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
New proposal: support for the google.api.HttpBody #904
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
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 is great, thank you so much for this! A couple of comments and I'm also wondering if you could put together something for the documentation as well? Along the lines of the patch examples: https://grpc-ecosystem.github.io/grpc-gateway/docs/patch.html.
runtime/marshaler.go
Outdated
@@ -16,7 +16,7 @@ type Marshaler interface { | |||
// NewEncoder returns an Encoder which writes bytes sequence into "w". | |||
NewEncoder(w io.Writer) Encoder | |||
// ContentType returns the Content-Type which this marshaler is responsible for. | |||
ContentType() string | |||
ContentType(v interface{}) string |
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.
I don't think we can change this without breaking backwards compatibility. Could we add a new interface with this new method and then type assert at marshalling time? That way we could support both new and old marshallers.
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.
Changed it back and assert it at marshalling time. What do you think of this implementation?
I signed it! |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
runtime/marshal_httpbodyproto.go
Outdated
// the actual message used as the response. If not, then this will | ||
// simply fallback to the JSONPb marshaler. | ||
type HTTPBodyMarshaler struct { | ||
DefaultMarshaler Marshaler |
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.
If you embed this directly you can avoid defining the methods which just call the underlying implementations:
type HTTPBodyMarshaler struct {
Marshaler
}
func SetHTTPBodyMarshaler(serveMux *ServeMux) {
serveMux.marshalers.mimeMap[MIMEWildcard] = &HTTPBodyMarshaler{
Marshaler: &JSONPb{OrigName: true},
}
}
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.
Adjusted.
"bytes" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
"google.golang.org/genproto/googleapis/api/httpbody" | ||
"testing" |
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.
Sorry, same thing about the imports please.
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.
Fixed.
What do you think about this? |
Codecov Report
@@ Coverage Diff @@
## master #904 +/- ##
==========================================
- Coverage 53.61% 53.54% -0.08%
==========================================
Files 39 40 +1
Lines 3937 3961 +24
==========================================
+ Hits 2111 2121 +10
- Misses 1629 1642 +13
- Partials 197 198 +1
Continue to review full report at Codecov.
|
Bump :D |
Not sure if it is added at the right place, but I added a small README for the httpbody :) |
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.
Great work, just a few comments on the new docs page.
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.
Thanks for picking this up!
No problem! |
I think that'd have to be part of your proto file annotation:
|
* Implementation of HTTPBody marshaler * Rework HTTPBodyMarshaler fallback marshaler * Added tests. * Fix gomod * Fixed tests and added two new ones. * Added marshal backwards compatibility * Last line modsum was removed. * Embedded Marshaler & fixed import order * Removed inherited methods. * Comment improvements * Added small readme. * Doc enhancements * Identation fix * What's wrong with identation
No description provided.