Skip to content
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

watch over grpc-gateway #5865

Closed
heyitsanthony opened this issue Jul 4, 2016 · 1 comment
Closed

watch over grpc-gateway #5865

heyitsanthony opened this issue Jul 4, 2016 · 1 comment

Comments

@heyitsanthony
Copy link
Contributor

(via #etcd)

Try:

curl localhost:2379/v3alpha/watch -d '{"request_union": {"create_request": {"key": "Zm9v"}}}}'

but get:

{"Error":"json: cannot unmarshal object into Go value of type etcdserverpb.isWatchRequest_RequestUnion","Code":2}

I attempted to figure out the correct syntax via encoding with grpc-gateway:

var protoReq WatchRequest                                                            
err = dec.Decode(&protoReq)                                                          
if err != nil {
    protoReq.RequestUnion = &WatchRequest_CreateRequest{ CreateRequest : &WatchCreateRequest{Key : []byte("abc") }}
    buf := new(bytes.Buffer)                                                     
    enc := marshaler.NewEncoder(buf)                                             
    err2 := enc.Encode(protoReq)                                                 
    b := buf.String()
    grpclog.Printf("Failed to decode request: %v \"%s\" %v", err, string(b), err2)    

Getting a potential JSON encoding back:

v3rpc/grpc: Failed to decode request: json: cannot unmarshal object into Go value of type etcdserverpb.isWatchRequest_RequestUnion "{"RequestUnion":{"CreateRequest":{"key":"YWJj"}}}" <nil>

Naturally, I try the value from Encode(protoReq), foolishly expecting Decode(Encode(x)) to work:

curl localhost:2379/v3alpha/watch -d '{"RequestUnion":{"CreateRequest":{"key":"YWJj"}}}'

but still an error:

{"Error":"unknown field \"RequestUnion\" in etcdserverpb.WatchRequest","Code":2}
@gyuho
Copy link
Contributor

gyuho commented Jul 5, 2016

Yeah this is not working in my machine as well.

curl -L http://localhost:2379/v3alpha/watch -X POST -d '{"request_union": {"create_request": {"key": "Zm9v"}}}}'

I tried to tag the WatchRequest manually, like:

type WatchRequest struct {
    // request_union is a request to either create a new watcher or cancel an existing watcher.
    //
    // Types that are valid to be assigned to RequestUnion:
    //  *WatchRequest_CreateRequest
    //  *WatchRequest_CancelRequest
    RequestUnion isWatchRequest_RequestUnion `protobuf:"varint,3,opt,name=request_union,proto3" json:"request_union,omitempty protobuf_oneof:"request_union""`
}

but still doesn't work.

And I think upstream is aware of this issue here grpc-ecosystem/grpc-gateway#82.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants