-
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 output field as an array of json values? #449
Comments
It looks like maybe? https://godoc.org/github.com/golang/protobuf/ptypes/struct#ListValue Just figuring out how to use it now. |
ListValue did it. It looks like one probably can use those types to force whatever json kinds one wants @yugui Do you want me to contrib some docs to help the next person? |
@MaerF0x0 a documentation addition for this would be /super/ helpful for other folks down the line. Please do! |
@MaerF0x0, to echo Travis' comment, even a code snippet in here would be really interesting to see. Thanks for digging in! I'm going to close this PR since it seems you've got it figured out but I would like to see if it's possible to add some docs on this. |
So I finally figure how to abuse grpc-gateway to make it have the HTTP interface we want, but now the go code is heinous. :-/
but the outgoing go looks like this (absurd). srv.Send(&somesvc.SomeListValues{
Row: &structpb.ListValue{
Values: []*structpb.Value{
&structpb.Value{Kind: &structpb.Value_StringValue{StringValue: "a"}},
&structpb.Value{Kind: &structpb.Value_NumberValue{NumberValue: 1.0}},
&structpb.Value{Kind: &structpb.Value_BoolValue{BoolValue: false}},
&structpb.Value{Kind: &structpb.Value_NullValue{NullValue: structpb.NullValue_NULL_VALUE}},
},
},
}) ideally it would just be: srv.Send([]interface{}{"a", 1.0, true, nil}) |
@achew22 Let me know if you'd like some docs surrounding ^^? I learned how to use the google well known types to make GRPC-gateway have the interface I like, but it also means the GRPCServer interface becomes gnarly. |
I'm not 100% sure on this since I can't see your code, but I would bet that you could create a helper method much like proto.String (or the other types) like this:
Usage might look like:
Or you could write an even more high level abstraction to translate from (I wouldn't do this, it feels kind of icky)
That said, you're not forced to use go as your langage for server writing. If you think you can do better in python, c++, javascript or any of the other gRPC languages you can write your server in that. |
If it makes it easier they can be the "simple" types (number, bool, null, string ... not array or object)
I'm trying to send a message like
my.proto:
I would like it to be
{"items":{"data": ["hi", 123, false, null]}}
bytes
gives me a base64 encoded stringrepeated bytes
gives me an array of base64 encoded stringsThe text was updated successfully, but these errors were encountered: