-
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
how to provide interface type inside proto for grpc-gateway #723
Comments
Unfortunately, proto doesn't really support union types. The only way I can think of doing this is to always take a string. I believe the json parser is nice enough to cast numbers into strings but I'm not 100% sure on that. You might also consider looking into one_of types, but I don't think they exactly provide these semantics. |
oneof not helps:
|
if i'm provide string, i have error that can't unmarshal to my type.
|
Huh, I guess it really doesn't support them. The only other option I can think of is writing your own marshaller for jspb or writing an interceptor in http land that rewrites the request. Sorry! |
@achew22 nice, can you provide link to doc how to write such interceptor? |
Unfortunately I don't think we have docs that demonstrate that. If you decide to go that route, it would be great if you could add some documentation into the |
@vtolstov Just to add to what @achew22 already wrote, I think what this means is just implementing a |
And the same for any replies, of course. It's called http Middleware: https://hackernoon.com/simple-http-middleware-with-go-79a4ad62889b. |
Random thought, partially based on @achew22's comment (I almost suggested implementing
I have, obviously, not tried this, and I have definitely not run this. |
@ivucica thanks! i'm try this |
That's a very clever idea! Good thinking @ivucica |
@ivucica not worked =(
define IntAndString in proto file like:
in other proto file use IntAndString image = 5; when i'm send int i have :
if i don't define in proto type IntAndString i fails to generate:
|
ping... |
I won't get around to playing with this out any time soon. What have you tried to triage this? Does I am also confused at which For instance, you can use gdb for debugging, or even better use Delve. I have done neither, but if I needed to triage what happens, I would find the source code line that prints cannot unmarshal number into Go value of type, add a breakpoint to it, then get the backtrace (in GDB, that's Once again, I have not used a debugger with Go code, and I have not tried to do what you want to do here. I think
That makes sense, right? |
This is not an issue with the library itself, so I will close this, though it contains some interesting information. Please feel free to reply in-line again, or make a case for keeping this open :). |
I have json message with some field image that can holds uint32 or string.
How can i specify such thing inside proto file? Or how to not decode this filed and get raw data for it?
The text was updated successfully, but these errors were encountered: