Skip to content

Commit

Permalink
Add FieldMask demo method
Browse files Browse the repository at this point in the history
  • Loading branch information
johanbrandhorst committed Apr 2, 2018
1 parent 807d213 commit 6c21737
Show file tree
Hide file tree
Showing 9 changed files with 553 additions and 40 deletions.
9 changes: 6 additions & 3 deletions Makefile
Expand Up @@ -27,18 +27,21 @@ generate:
--gogo_out=plugins=grpc,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api:\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$$GOPATH/src/ \
--grpc-gateway_out=\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api:\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$$GOPATH/src/ \
--swagger_out=third_party/OpenAPI/ \
--govalidators_out=gogoimport=true,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api:\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$$GOPATH/src \
proto/example.proto

Expand Down

3 comments on commit 6c21737

@wolfinger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm trying to replicate this for my own app and am getting the following compile error: generated/api/v1/acct_service.pb.gw.go:128:24: cannot use fieldMask (type *fieldmaskpb.FieldMask) as type *types.FieldMask in assignment

i believe the issue might be related to grpc-ecosystem/grpc-gateway#812 where the grpc gateway will automatically populate a fieldmask using the json request. that fieldmask type is using the standard protobuf fieldmask type while gogo is using an identically structured, but different fieldmask type.

please note i'm a go beginner and programming is not my day job, so apologize if i'm missing something obvious or not using correct terminology.

@johanbrandhorst
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wolfinger, I wrote a blog post about these sort of errors a while back: https://jbrandhorst.com/post/gogoproto/. My recommendation nowadays is just to avoid using gogo protobuf altogether. You can make it work but there are both obvious and non obvious warts in the process and it's not worth the potential speed increase.

@wolfinger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super helpful @johanbrandhorst, thanks so much. looks like it's time for a refactor!

Please sign in to comment.