From a6e158ab0cc0bf3e289cec93f1f3eb7c3631b5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Rasc=C3=A3o?= Date: Wed, 28 Jul 2021 01:34:46 +0100 Subject: [PATCH] Switch protobuf generation to buf cli tool (#720) Current generation of protobuf stubs is hard and there's open issues around it: https://github.com/grpc-ecosystem/grpc-gateway/issues/1065 grpc-gateway author and README suggest to use `buf` instead which intends to be a simpler and more reliable method of protobuf stub generation. --- gctrpc/README.md | 31 +++++++++++++++++++++---------- gctrpc/buf.gen.yaml | 17 +++++++++++++++++ gctrpc/buf.lock | 17 +++++++++++++++++ gctrpc/buf.yaml | 5 +++++ go.mod | 1 - 5 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 gctrpc/buf.gen.yaml create mode 100644 gctrpc/buf.lock create mode 100644 gctrpc/buf.yaml diff --git a/gctrpc/README.md b/gctrpc/README.md index 8fcfde78..d881b39e 100644 --- a/gctrpc/README.md +++ b/gctrpc/README.md @@ -36,10 +36,11 @@ manager or by downloading one of the releases from the official repository: Then use `go get` to download the following packages: ```bash -go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway -go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 -go get google.golang.org/protobuf/cmd/protoc-gen-go -go get google.golang.org/grpc/cmd/protoc-gen-go-grpc +go get \ + github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \ + github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \ + google.golang.org/protobuf/cmd/protoc-gen-go \ + google.golang.org/grpc/cmd/protoc-gen-go-grpc ``` This will place the following binaries in your `$GOBIN`; @@ -51,15 +52,25 @@ This will place the following binaries in your `$GOBIN`; Make sure that your `$GOBIN` is in your `$PATH`. -## Usage +### Linux / macOS + +GoCryptoTrader requires a local installation of the `buf` cli tool that tries to make Protobuf handling more easier and reliable, +after [installation](https://docs.buf.build/installation) you'll need to run: + +```shell +buf beta mod update +``` + +After previous command, make necessary changes to the `rpc.proto` spec file and run the generation command: + +```shell +buf generate +``` + +### Windows After the above dependencies are required, make necessary changes to the `rpc.proto` spec file and run the generation scripts: -### Windows - Run `gen_pb_win.bat` -### Linux and macOS - -Run `./gen_pb_linux.sh` diff --git a/gctrpc/buf.gen.yaml b/gctrpc/buf.gen.yaml new file mode 100644 index 00000000..78bbd4ff --- /dev/null +++ b/gctrpc/buf.gen.yaml @@ -0,0 +1,17 @@ +version: v1beta1 +plugins: + - name: go + out: ./ + opt: + - paths=source_relative + - name: go-grpc + out: ./ + opt: + - paths=source_relative + - name: grpc-gateway + out: ./ + opt: + - paths=source_relative + - generate_unbound_methods=true + - name: openapiv2 + out: ./ diff --git a/gctrpc/buf.lock b/gctrpc/buf.lock new file mode 100644 index 00000000..69996d24 --- /dev/null +++ b/gctrpc/buf.lock @@ -0,0 +1,17 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: beta + repository: googleapis + branch: main + commit: 1c473ad9220a49bca9320f4cc690eba5 + digest: b1-unlhrcI3tnJd0JEGuOb692LZ_tY_gCGq6mK1bgCn1Pg= + create_time: 2021-06-23T20:16:47.788079Z + - remote: buf.build + owner: grpc-ecosystem + repository: grpc-gateway + branch: main + commit: d19475fa22444a289c46af009acce62c + digest: b1-_zhDPyr_Ctc1QRAKuad6_0xvoyPd6QaB22ldm9gzS0Q= + create_time: 2021-04-26T15:19:26.742789Z diff --git a/gctrpc/buf.yaml b/gctrpc/buf.yaml new file mode 100644 index 00000000..5680ff51 --- /dev/null +++ b/gctrpc/buf.yaml @@ -0,0 +1,5 @@ +version: v1beta1 +name: buf.build/gocryptotrader/grpc +deps: + - buf.build/beta/googleapis + - buf.build/grpc-ecosystem/grpc-gateway diff --git a/go.mod b/go.mod index 08887bab..020c0d16 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/d5/tengo/v2 v2.8.0 github.com/friendsofgo/errors v0.9.2 // indirect github.com/gofrs/uuid v4.0.0+incompatible - github.com/golang/protobuf v1.5.2 github.com/google/go-querystring v1.1.0 github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.4.2