Tag Archives: grpc
Golang. Adding a json body to POST request in protofile
It could be a bit tricky, and I failed to find a good example for it.
Useful links for proto generator development
https://rotemtam.com/2021/03/22/creating-a-protoc-plugin-to-gen-go-code/ https://medium.com/@tim.r.coulson/writing-a-protoc-plugin-with-google-golang-org-protobuf-cd5aa75f5777 https://github.com/nametake/protoc-gen-gohttp https://github.com/drekle/protoc-gen-goexample/blob/c60883c9711f3cfbd5191fd697651dbd067e6fdd/main.go#L135 https://github.com/grpc-ecosystem/grpc-gateway/blob/24434e22fb9734f1a62c81c4ea246125d7844645/examples/internal/proto/examplepb/echo_service_grpc.pb.go https://pkg.go.dev/google.golang.org/protobuf/compiler/protogen#Options.Run https://github.com/lyft/protoc-gen-star https://go.dev/blog/protobuf-apiv2 https://docs.buf.build/build/usage/#configuration https://github.com/grpc-ecosystem/grpc-gateway https://github.com/googleapis/googleapis/tree/master/google/api https://github.com/bufbuild/buf https://stackoverflow.com/questions/36540427/cannot-find-package-google-protobuf https://pkg.go.dev/google.golang.org/protobuf https://developers.google.com/protocol-buffers/docs/reference/go-generated#package https://stackoverflow.com/questions/61666805/correct-format-of-protoc-go-package https://grpc.io/docs/languages/go/quickstart/ https://github.com/protocolbuffers/protobuf/tree/master/src/google/protobuf https://github.com/gogo/protobuf/blob/b03c65ea87cdc3521ede29f62fe3ce239267c1bc/protobuf/google/protobuf/descriptor.proto
Nullable fields in json generated from protobuf file
Native support With grpc v2 for go, protofile’s optional option is supported, so you don’t need to import proto extensions anymore and use things like google.protobuf.StringValue. my.proto message FeeView { optional string name = 1 [json_name = «name»]; } go mapper var name *string if fee.Name != nil { name = &fee.Name } fee := …
Complete list of swagger options to protobuf file
Here is an example with many options that help generate proper swagger out of protofile. Original URL — https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/examples/internal/proto/examplepb/a_bit_of_everything.proto.
GRPC fallback to Rest API with custom field names
When you generate JSON for Rest API from proto-file, protoc-gen-gofast generates field names for JSON in lowerCamelCase format while most of the Rest APIs use snake_case for that. And if you want to replace some legacy API with your new implementation without breaking backward compatibility, you need to fix it. There could be different ways …
Interesting alternative to grpc_cli
https://github.com/ktr0731/evans It has REPL mode and CLI mode for e2e tests I think, it could be a good alternative to grpc_cli.
Installing protobuf tools on MacOS
Installing protoc brew install protobuf Or follow different instructions. Installing grpc_cli Option 1. Easy way. brew tap grpc/grpc brew install —with-plugins grpc It is described here — https://github.com/grpc/homebrew-grpc. Option 2. Hard way — using cmake and make. NOT RECOMMENDED. brew install autoconf automake libtool shtool cmake git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc cd grpc …
Golang: testing http and grpc servers
HTTP server is quite easy to test — here is a nice video about it:
How to make grpc call from shell
1 https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md grpc_cli call localhost:7020 ChatAPI.GetChats «external_user:{id:’30594028′,type:1}, limit:10, offset:0, order:ORDER_DESC, requested_by_external_user:{id:’30594028′,type:1},with_unread_count:true» 2 https://github.com/fullstorydev/grpcurl grpcurl -plaintext -emit-defaults -d ‘{«lozon_id»: 15515160432000}’ -H ‘User-Name: grpcurl’ localhost:7020 points/FindPointByLozonID