Skip to content

Commit f2e74d6

Browse files
Adapt usage instructions to use protoc-gen-go-grpc (#1755)
* Adapt usage instructions to use protoc-gen-go-grpc This reflect recent changes in https://grpc.io/docs/languages/go/quickstart/ to use new protoc-gen-go-grpc. Also remove a duplicated paragraph. * Readme: use new protoc-gen-go Replace github.com/golang/protobuf/protoc-gen-go by google.golang.org/protobuf/cmd/protoc-gen-go * Update other instructions to use protoc-gen-go-grpc * Use --x-opt in instructions * Update docs/_docs/usegotemplates.md Co-authored-by: Johan Brandhorst-Satzkorn <[email protected]> * Use go get instead of go get -u Co-authored-by: Johan Brandhorst-Satzkorn <[email protected]>
1 parent e2913ce commit f2e74d6

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
- [ ] Update your protoc to the [latest version](https://github.com/google/protobuf/releases).
55
- [ ] Update your copy of the `grpc-gateway` library to the latest version from github:
66
```sh
7-
go get -u github.com/grpc-ecosystem/grpc-gateway
7+
go get github.com/grpc-ecosystem/grpc-gateway/v2@latest
88
```
99
- [ ] Delete the `protoc-gen-grpc-gateway` and `protoc-gen-openapiv2` binary from your `PATH`,
1010
and reinstall the latest versions:
1111
```sh
12-
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
13-
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-openapiv2
12+
go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
13+
go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
1414
```
1515

1616
## I still have a problem!

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ package tools
6262
import (
6363
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
6464
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
65-
_ "github.com/golang/protobuf/protoc-gen-go"
65+
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
66+
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
6667
)
6768
```
6869

@@ -72,14 +73,16 @@ Run `go mod tidy` to resolve the versions. Install by running
7273
$ go install \
7374
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
7475
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
75-
github.com/golang/protobuf/protoc-gen-go
76+
google.golang.org/protobuf/cmd/protoc-gen-go \
77+
google.golang.org/grpc/cmd/protoc-gen-go-grpc
7678
```
7779

78-
This will place three binaries in your `$GOBIN`;
80+
This will place four binaries in your `$GOBIN`;
7981

8082
* `protoc-gen-grpc-gateway`
8183
* `protoc-gen-openapiv2`
8284
* `protoc-gen-go`
85+
* `protoc-gen-go-grpc`
8386

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

@@ -108,7 +111,10 @@ Make sure that your `$GOBIN` is in your `$PATH`.
108111
Here's an example of what a `protoc` command might look like to generate Go stubs:
109112

110113
```sh
111-
protoc -I . --go_out ./gen/go/ --go_opt plugins=grpc --go_opt paths=source_relative your/service/v1/your_service.proto
114+
protoc -I . \
115+
--go_out ./gen/go/ --go_opt paths=source_relative \
116+
--go-grpc_out ./gen/go/ --go-grpc_opt paths=source_relative \
117+
your/service/v1/your_service.proto
112118
```
113119

114120
3. Implement your service in gRPC as usual
@@ -178,11 +184,6 @@ Make sure that your `$GOBIN` is in your `$PATH`.
178184
+ }
179185
}
180186
```
181-
>You will need to provide the required third party protobuf files to the `protoc` compiler.
182-
>They are included in this repo under the `third_party/googleapis` folder, and we recommend copying
183-
>them into your `protoc` generation file structure. If you've structured your proto files according
184-
>to something like [the Buf style guide](https://buf.build/docs/style-guide#files-and-packages),
185-
>you could copy the files into a top-level `./google` folder.
186187
187188
>You will need to provide the required third party protobuf files to the `protoc` compiler.
188189
>They are included in this repo under the `third_party/googleapis` folder, and we recommend copying

docs/_docs/cygwin.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@ From an elevated cmd.exe prompt set the GOPATH variable in Windows and add the `
3535

3636
Then `go get -u -v` the following packages:
3737

38-
go get -u -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
39-
go get -u -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-openapiv2
40-
go get -u -v github.com/golang/protobuf/protoc-gen-go
38+
go get -u -v github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
39+
go get -u -v github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
40+
go get -u -v google.golang.org/protobuf/cmd/protoc-gen-go
41+
go get -u -v google.golang.org/grpc/cmd/protoc-gen-go-grpc
4142

4243
This will probably fail with a similar output to this:
4344

4445
github.com/grpc-ecosystem/grpc-gateway (download)
4546
# cd .; git clone https://github.com/grpc-ecosystem/grpc-gateway C:\path\to\your\cygwin\home\user\go\src\github.com\grpc-ecosystem\grpc-gateway
4647
Cloning into 'C:\path\to\your\cygwin\home\user\go\src\github.com\grpc-ecosystem\grpc-gateway'...
4748
fatal: Invalid path '/home/user/go/C:\path\to\your\cygwin\home\user\go\src\github.com\grpc-ecosystem\grpc-gateway': No such file or directory
48-
package github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway: exit status 128
49+
package github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway: exit status 128
4950

5051
To fix this you need to run the `go get -u -v` commands and look for all lines starting with `# cd .;`.
5152
Copy and paste these lines into your shell and change the clone destination directories.
@@ -63,7 +64,7 @@ Follow the [instructions](https://github.com/grpc-ecosystem/grpc-gateway#usage)
6364

6465
Adjust steps 3, 5 and 7 like this. protoc expects native Windows paths.
6566

66-
protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. ./path/to/your_service.proto
67+
protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=. --go-grpc_out=. ./path/to/your_service.proto
6768
protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. ./path/to/your_service.proto
6869
protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --openapiv2_out=logtostderr=true:. ./path/to/your_service.proto
6970

docs/_docs/grpcapiconfiguration.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This is similar to how [Cloud Endpoints behaves](https://cloud.google.com/endpoi
2121
* URI path is built from the service's name and method: `/<fully qualified service name>/<method name>` (e.g.: `/my.package.EchoService/Echo`)
2222
* HTTP body is the serialized protobuf message.
2323

24-
NOTE: the same option is also supported by the `gen-swagger` plugin.
24+
NOTE: the same option is also supported by the `gen-openapiv2` plugin.
2525

2626
## Using an external configuration file
2727
Google Cloud Platform offers a way to do this for services hosted with them called ["gRPC API Configuration"](https://cloud.google.com/endpoints/docs/grpc/grpc-service-config). It can be used to define the behavior of a gRPC API service without modifications to the service itself in the form of [YAML](https://en.wikipedia.org/wiki/YAML) configuration files.
@@ -66,7 +66,12 @@ The following is equivalent to the basic [usage example](usage.html) but without
6666
3. Generate gRPC stub as before
6767
6868
```sh
69-
protoc -I. --go_out=plugins=grpc,paths=source_relative:./gen/go/ your/service/v1/your_service.proto
69+
protoc -I . \
70+
--go_out ./gen/go/ \
71+
--go_opt paths=source_relative \
72+
--go-grpc_out ./gen/go/ \
73+
--go-grpc_opt paths=source_relative \
74+
your/service/v1/your_service.proto
7075
```
7176
7277
It will generate a stub file with path `./gen/go/your/service/v1/your_service.pb.go`.
@@ -77,7 +82,11 @@ The following is equivalent to the basic [usage example](usage.html) but without
7782
the `your_service.yaml` in addition to the .proto file:
7883
7984
```sh
80-
protoc -I. --grpc-gateway_out=logtostderr=true,paths=source_relative,grpc_api_configuration=path/to/your_service.yaml:./gen/go \
85+
protoc -I . \
86+
--grpc-gateway_out ./gen/go \
87+
--grpc-gateway_opt logtostderr=true \
88+
--grpc-gateway_opt paths=source_relative \
89+
--grpc-gateway_opt grpc_api_configuration=path/to/your_service.yaml \
8190
your/service/v1/your_service.proto
8291
```
8392
@@ -86,24 +95,25 @@ The following is equivalent to the basic [usage example](usage.html) but without
8695
6. Generate the optional your_service.swagger.json
8796
8897
```sh
89-
protoc -I . --swagger_out ./gen/go \
90-
--swagger_opt grpc_api_configuration=path/to/your_service.yaml \
98+
protoc -I . --openapiv2_out ./gen/go \
99+
--openapiv2_opt grpc_api_configuration=path/to/your_service.yaml \
91100
your/service/v1/your_service.proto
92101
```
93102
94103
or using an OpenAPI configuration file
95104
96105
```sh
97-
protoc -I . --swagger_out ./gen/go \
98-
--swagger_opt grpc_api_configuration=path/to/your_service.yaml \
99-
--swagger_opt openapi_configuration=path/to/your_service_swagger.yaml \
106+
protoc -I . --openapiv2_out ./gen/go \
107+
--openapiv2_opt grpc_api_configuration=path/to/your_service.yaml \
108+
--openapiv2_opt openapi_configuration=path/to/your_service_swagger.yaml \
100109
your/service/v1/your_service.proto
101110
```
102111
103112
For an example of an OpenAPI configuration file, see [unannotated_echo_service.swagger.yaml](https://github.com/grpc-ecosystem/grpc-gateway/tree/master/examples/internal/proto/examplepb/unannotated_echo_service.swagger.yaml), which adds OpenAPI options to [unannotated_echo_service.proto](https://github.com/grpc-ecosystem/grpc-gateway/tree/master/examples/internal/proto/examplepb/unannotated_echo_service.proto).
104113
105114
```sh
106-
protoc -I. --swagger_out=grpc_api_configuration=path/to/your_service.yaml:./gen/go \
115+
protoc -I . --openapiv2_out ./gen/go \
116+
--openapiv2_opt grpc_api_configuration=path/to/your_service.yaml \
107117
your/service/v1/your_service.proto
108118
```
109119

docs/_docs/usegotemplates.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ as:
1515
## How to use it
1616

1717
By default this function is turned off, so if you want to use it you
18-
have to set the `use_go_templates` flag to true inside of the
19-
`openapiv2_out` flag.
18+
have to add the `use_go_templates` option:
19+
20+
```shell
21+
--openapiv2_out . --openapiv2_opt use_go_templates=true
22+
```
23+
24+
or:
2025

2126
```shell
2227
--openapiv2_out=use_go_templates=true:.
@@ -28,9 +33,11 @@ Example of a bash script with the `use_go_templates` flag set to true:
2833

2934
```shell
3035
$ protoc -I. \
31-
--go_out=plugins=grpc:. \
32-
--grpc-gateway_out=logtostderr=true:. \
33-
--openapiv2_out=logtostderr=true,use_go_templates=true:. \
36+
--go_out . --go-grpc_out . \
37+
--grpc-gateway_out . --grpc-gateway_opt logtostderr=true \
38+
--openapiv2_out . \
39+
--openapiv2_opt logtostderr=true \
40+
--openapiv2_opt use_go_templates=true \
3441
path/to/my/proto/v1/myproto.proto
3542
```
3643

0 commit comments

Comments
 (0)