-
Notifications
You must be signed in to change notification settings - Fork 806
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
gogoproto.stdtime = true
is causing a panic error of interface conversion: *time.Time is not proto.Message: missing method ProtoMessage
#212
Comments
I believe (as we discussed on #grpc in the Gophers Slack) that this is caused by mixing grpc-gateway with Gogo. grpc-gateway uses
It's assuming that any struct it finds is marshalable as a Gogo has its own fork of So the problem at the moment is that grpc-gateway can't be used with Gogo. I don't think you can tell grpc-gateway to use a different JSON marshaler, either. From what I can tell, it's not possible. |
Upon further investigation, you can use this marshaler from CockroachDB, which can plug into grpc-gateway like so: m := new(protoutil.JSONPb)
runtime.NewServeMux(runtime.WithMarshalerOption(runtime.MIMEWildcard, m)) |
Should this issue stay open? |
Pretty sure I addressed it. |
I agree :) Maybe we could ask @tamird to factor this out into something that everyone can use? |
Wasn't there an issue in https://github.com/grpc-ecosystem/grpc-gateway that tracked such an extraction? |
@atombender, @awalterschulze: It sill doesn't work well for me, even with the
And yet, the timestamp itself doesn't marshaled into JSON as a valid timestamp: {
"value": {
"timestamp": "0001-01-01T00:00:00.000Z"
}
} Attached an updated gist. |
@awalterschulze Based on @atombender's example, adding these options to my
The issue occurs again as soon as they are defined with a |
Thats is quite interesting. I'll have to make a test case for that and check it. I assume it is call GetProperties in generator.go and when the Marshal() method is generated it skips this call. I don't know what the fix is yet, but since the json is marshaled correctly, I assume this is low priority. |
@tamird ^^ doesn't seem like the issue was ever opened |
I have changed test/types/types.proto to have a sizer_all=false message StdTypes {
google.protobuf.Timestamp nullableTimestamp = 1 [(gogoproto.stdtime) = true];
google.protobuf.Duration nullableDuration = 2 [(gogoproto.stdduration) = true];
google.protobuf.Timestamp timestamp = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
google.protobuf.Duration duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
} Which also gives me a pointer to time.Time in the resulting struct. |
@awalterschulze It works well for me since I changed the marshaler used by grpc-gateway (as we discussed on #216). Sorry that I haven't updated here, I was a bit busy the last few days. |
Ok cool. So we can close this issue again? |
@awalterschulze Pretty sure we can. |
Sweet Thank you |
I just hit this issue again. Is the cockroach jsonpb module still the best way to address this problem? |
Looks like it. |
@Mistobaan FYI, there's now an "official" package dealing with this: https://github.com/gogo/gateway. See https://github.com/gogo/grpc-example for an example of this in use. |
3 days of researching and i found a solution. Just in case someone having this issue and can`t find an answer try adding this to proto file |
I'm having a similar issue as reported in #209. I'm getting the following runtime (panic) error using
[(gogoproto.stdtime) = true]
:It is worth mentioning that with the standard timestamp.Timestamp from golang/protobuf it works fine (even through grpc-gateway).
Attached a gist with the relevant files.
Any help will be much appreciated!
The text was updated successfully, but these errors were encountered: