Skip to content

Instantly share code, notes, and snippets.

@czyang
Last active July 3, 2019 14:32
Show Gist options
  • Select an option

  • Save czyang/6d34bba5cdc80ddfcccd52b3e850d205 to your computer and use it in GitHub Desktop.

Select an option

Save czyang/6d34bba5cdc80ddfcccd52b3e850d205 to your computer and use it in GitHub Desktop.

Install openapi2proto

go get -u github.com/NYTimes/openapi2proto/cmd/openapi2proto

Install protobuff, grpc https://grpc.io/docs/quickstart/go/

$ go get -u google.golang.org/grpc
$ go get -u github.com/golang/protobuf/protoc-gen-go

Generate protobuf code (*.proto)

openapi2proto -spec spec_file.yaml -annotate > output.proto

Generate grpc code (*.pb.go)

protoc -I/usr/local/include -I. \
  -I$GOPATH/src \
  -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
  --go_out=plugins=grpc:. \
  ./path/to/*.proto

Generate grpc gateway code (*.pb.gw.go)

protoc -I/usr/local/include -I. \
  -I$GOPATH/src \
  -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
  --grpc-gateway_out=logtostderr=true:. \
  ./path/to/*.proto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment