Skip to content

Commit

Permalink
Switch protobuf generation to buf cli tool
Browse files Browse the repository at this point in the history
Current generation of protobuf stubs is hard and there's open issues
around it:
   grpc-ecosystem/grpc-gateway#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.
  • Loading branch information
lrascao committed Jul 22, 2021
1 parent e1eceea commit 9b98194
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 288 deletions.
2 changes: 1 addition & 1 deletion engine/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/gofrs/uuid"
grpcauth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/common/file"
Expand Down
37 changes: 5 additions & 32 deletions gctrpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,12 @@ be toggled on or off depending on the users preference.

## Installation

GoCryptoTrader requires a local installation of the Google protocol buffers
compiler `protoc` v3.0.0 or above. Please install this via your local package
manager or by downloading one of the releases from the official repository:
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:

[protoc releases](https://github.com/protocolbuffers/protobuf/releases)
$ buf beta mod update

Then use `go get` to download the following packages:
After previous command, make necessary changes to the `rpc.proto` spec file and run the generation command:

```bash
go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get google.golang.org/protobuf/cmd/protoc-gen-go
go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
```
$ buf generate

This will place three binaries in your `$GOBIN`;

* `protoc-gen-grpc-gateway`
* `protoc-gen-swagger`
* `protoc-gen-go`
* `protoc-gen-go-grpc`

Make sure that your `$GOBIN` is in your `$PATH`.

## Usage

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`
15 changes: 15 additions & 0 deletions gctrpc/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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
17 changes: 17 additions & 0 deletions gctrpc/buf.lock
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions gctrpc/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: v1beta1
name: buf.build/gocryptotrader/grpc
deps:
- buf.build/beta/googleapis
- buf.build/grpc-ecosystem/grpc-gateway
512 changes: 257 additions & 255 deletions gctrpc/rpc.pb.gw.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.4.2
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0
github.com/kat-co/vala v0.0.0-20170210184112-42e1d8b61f12
github.com/kr/text v0.2.0 // indirect
Expand Down

0 comments on commit 9b98194

Please sign in to comment.