Giter Site home page Giter Site logo

Comments (13)

yugui avatar yugui commented on May 2, 2024 1

@gyuho
I am not yet confident but I suspect if this proto in (*WatchRequest).XXX_OneofFuncs,

func (*WatchRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {

at https://github.com/gyuho/etcd/blob/3108859828f851e9a46772fe8e16d257b40f3639/etcdserver/etcdserverpb/rpc.pb.go#L1084
should have been github.com/golang/protobuf/proto but not github.com/gogo/protobuf/proto so that it is compatible to https://github.com/golang/protobuf/blob/ba6f978a1a6606adf3ccb6987f15c64262bfdbc2/proto/properties.go#L729.

from grpc-gateway.

johansja avatar johansja commented on May 2, 2024

Use of https://godoc.org/github.com/golang/protobuf/jsonpb instead of encoding/json can help.

from grpc-gateway.

yugui avatar yugui commented on May 2, 2024

@johansja Thank you. Yes, it is #79.

from grpc-gateway.

gyuho avatar gyuho commented on May 2, 2024

@yugui etcd is hitting this issue, though it's happening only in experimental feature.

Do we have any workaround for this? Or ETA to support this?

Thanks!

from grpc-gateway.

johansja avatar johansja commented on May 2, 2024

You should be able to use one_of with the help of runtime.WithMarshalerOption.

from grpc-gateway.

yugui avatar yugui commented on May 2, 2024

Now the default marshaller uses 'jsonpb'. So I think it is supported.

@gyuho Could you re-confirm with the HEAD of the master branch?
Let me know if you still have the issue.
I'll close this issue if otherwise.

from grpc-gateway.

gyuho avatar gyuho commented on May 2, 2024

@yugui First thanks for helping debug this.

etcd still complains {"Error":"json: cannot unmarshal object into Go value of type etcdserverpb.isWatchRequest_RequestUnion","Code":2}. And tried the latest master branch of grpc-gateway and golang/protobuf, and regenerate the gateway files, as here etcd-io/etcd@8759230.

I added reflect.TypeOf(marshaler) to this line https://github.com/gyuho/etcd/blob/3108859828f851e9a46772fe8e16d257b40f3639/etcdserver/etcdserverpb/rpc.pb.gw.go#L91 and confirm that *runtime.JSONPb typed marshaler is being used, but still seeting that error.

*runtime.JSONPb
2016-07-06 22:07:13.861689 I | v3rpc/grpc: Failed to decode request: json: cannot unmarshal object into Go value of type etcdserverpb.isWatchRequest_RequestUnion

Maybe we generate gateway files in the wrong way? I tried to regenerate *.gw.go files but don't see any diff.

Thanks.

from grpc-gateway.

yugui avatar yugui commented on May 2, 2024

@gyuho I see. I'll take a look.

from grpc-gateway.

yugui avatar yugui commented on May 2, 2024

@gyuho
Does this work fine?

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

You need to specify literally one of the fields grouped by request_union.

from grpc-gateway.

gyuho avatar gyuho commented on May 2, 2024

@yugui Still doesn't seem to work.

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

{"Error":"unknown field \"create_request\" in etcdserverpb.WatchRequest","Code":2}

Thanks!

from grpc-gateway.

yugui avatar yugui commented on May 2, 2024

@gyuho
It does not look to be an issue of grpc-gateway. I could reproduce the issue without grpc-gateway.

package main

import (
        "log"

        "github.com/coreos/etcd/etcdserver/etcdserverpb"
        "github.com/golang/protobuf/jsonpb"
)

func main() {
        const input = `{"create_request": {"key": "Zm9v"}}`
        var protoReq etcdserverpb.WatchRequest
        if err := jsonpb.UnmarshalString(input, &protoReq); err != nil {
                log.Fatal(err)
        }
}
$ go run main.go
2016/07/12 12:15:28 unknown field "create_request" in etcdserverpb.WatchRequest
exit status 1

I don't know what the root cause actually is, but I suspect incompatibility between github.com/golang/protobuf/jsonpb and gogoproto.

from grpc-gateway.

yugui avatar yugui commented on May 2, 2024

@gyuho Confirmed in https://gist.github.com/yugui/4425e705680fb4f6c99423b99b8a83d2

$ go get gist.github.com/4425e705680fb4f6c99423b99b8a83d2.git
$ go build -o test gist.github.com/4425e705680fb4f6c99423b99b8a83d2.git
$ ./test
$ echo $?
0
$ go build --tags=gogo -o test gist.github.com/4425e705680fb4f6c99423b99b8a83d2.git
$ ./test
2016/07/12 12:53:05 unknown field "create_request" in main.WatchRequest
$ echo $?
1

from grpc-gateway.

gyuho avatar gyuho commented on May 2, 2024

@yugui I will see if I can find some workarounds or file an issue to gogoproto. Thanks a lot!

from grpc-gateway.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.