Skip to content

Commit c5cbcc5

Browse files
committed
feat(proto): buf generate
1 parent cf03202 commit c5cbcc5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1493
-239
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ indent_size = 4
3030

3131
[Makefile]
3232
indent_style = tab
33+
34+
[*.proto]
35+
indent_size = 2
36+
indent_style = space
37+
insert_final_newline = true

.gitignore

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/macos,go,visualstudiocode,goland
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,go,visualstudiocode,goland
3+
14
### Go ###
5+
# If you prefer the allow list template instead of the deny list, see community template:
6+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
7+
#
28
# Binaries for programs and plugins
39
*.exe
410
*.exe~
@@ -12,8 +18,15 @@
1218
# Output of the go coverage tool, specifically when used with LiteIDE
1319
*.out
1420

21+
# Dependency directories (remove the comment below to include it)
22+
# vendor/
23+
24+
# Go workspace file
25+
go.work
26+
go.work.sum
27+
1528
### Go Patch ###
16-
# /vendor/
29+
/vendor/
1730
/Godeps/
1831

1932
# OS generated files #

apps/hello/go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
34
github.com/gomarkdown/markdown v0.0.0-20210408062403-ad838ccf8cdd/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU=
45
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
56
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
@@ -11,6 +12,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
1112
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1213
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1314
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
15+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1416
golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
1517
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
1618
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -21,3 +23,4 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
2123
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2224
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2325
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
26+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

buf.gen.yaml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
11
version: v1
2-
32
managed:
43
enabled: true
54
go_package_prefix:
65
default: github.com/xmlking/grpc-starter-kit
76
except:
87
- buf.build/googleapis/googleapis
9-
- buf.build/envoyproxy/protoc-gen-validate
108
- buf.build/srikrsna/protoc-gen-gotag
9+
- buf.build/go-sdk/protoc-gen-validate
1110
java_multiple_files: true
1211
# java_package_prefix: com
1312

1413
plugins:
15-
- name: go
16-
out: .
17-
opt: paths=source_relative
1814
# FIXME: https://github.com/srikrsna/protoc-gen-gotag/issues/26
1915
# - name: gotag
2016
# out: .
2117
# opt:
2218
# - paths=source_relative
23-
- name: go-grpc
19+
- remote: buf.build/protocolbuffers/plugins/go:v1.28.0-1
2420
out: .
2521
opt:
2622
- paths=source_relative
27-
- require_unimplemented_servers=false
28-
- name: validate
23+
- remote: buf.build/grpc/plugins/go:v1.2.0-1
2924
out: .
3025
opt:
3126
- paths=source_relative
27+
- require_unimplemented_servers=false
28+
- remote: buf.build/go-sdk/plugins/protoc-gen-validate:v0.6.7-1
29+
out: .
30+
opt:
3231
- lang=go
33-
34-
# - name: descriptor_set
35-
# out: ./descriptor
36-
# file_sufix: bin
37-
# include_imports: true
38-
# include_source_info: true
32+
- paths=source_relative

dkit/bigquery/v1/bigquery_options.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dkit/bigquery/v1/bigquery_options.pb.validate.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dkit/privacy/v1/privacy_options.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dkit/privacy/v1/privacy_options.pb.validate.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/advanced/buf.md

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,56 @@
88

99
## Prerequisites
1010

11-
```bash
11+
```shell
1212
# buf: proto tool https://buf.build/docs/tour-1
13+
brew install bufbuild/buf/buf
1314
# or use `go install` to install Buf
1415
go install github.com/bufbuild/buf/cmd/buf@latest
1516

1617
# Install protoc plugins
1718
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
1819
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
1920
go install github.com/srikrsna/protoc-gen-gotag@latest
21+
22+
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
23+
# Installing PGV can currently only be done from source:
24+
# from user's home directory, run
25+
go get -d github.com/envoyproxy/protoc-gen-validate
26+
cd ~/go/src/github.com/envoyproxy/protoc-gen-validate
27+
git pull
28+
make build
2029
```
2130

31+
[Editor Integration](https://docs.buf.build/editor-integration) (Optional)
32+
![goland-buf-watch](../images/goland-buf-watch.png)
33+
Add `Import Paths` and `google/protobuf/descriptor.proto` in **GoLand/IntelliJ** as described [here](https://github.com/jvolkman/intellij-protobuf-editor/issues/33#issuecomment-898466971) 👇
34+
![goland-proto-import](../images/goland-proto-import.png)
35+
2236
## Developer Workflow
2337

2438
### Info
2539

26-
```bash
40+
```shell
2741
# To list all files Buf is configured to use:
2842
buf ls-files
2943
# To see your currently configured lint or breaking checkers:
30-
buf config ls-lint-rules
31-
buf config ls-breaking-rules
44+
buf mod ls-lint-rules
45+
buf mod ls-breaking-rules
3246
# To see all available lint checkers independent of configuration/defaults:
33-
buf config ls-lint-rules --all
47+
buf mod ls-lint-rules --all
3448
```
3549

3650
### Build
3751

38-
```bash
52+
```shell
3953
# check
4054
buf build -o /dev/null
4155
buf build -o image.bin
4256
```
4357

4458
### Lint
4559

46-
```bash
60+
```shell
4761
buf lint
4862
# We can also output errors in a format you can then copy into your buf.yaml file
4963
buf lint --error-format=config-ignore-yaml
@@ -61,13 +75,13 @@ buf breaking --against "$(HTTPS_GIT)#branch=main"
6175
### Generate
6276

6377
Cleanup
64-
```bash
78+
```shell
6579
rm -rf dkit
6680
rm -rf mkit
6781
```
6882

6983
Generate
70-
```bash
84+
```shell
7185
buf generate proto/dkit
7286
buf generate proto/mkit
7387
buf generate
@@ -84,16 +98,18 @@ Buf support modules [dependencies](https://docs.buf.build/tour/add-a-dependency)
8498
#### Login to buf registry.
8599
This command will create `/Users/<username>/.netrc` file
86100

87-
```bash
101+
```shell
88102
# fill the username and token
89-
BUF_USER=
90-
BUF_API_TOKEN=
103+
export BUF_USER=chintha
104+
export BUF_API_TOKEN=
91105
echo ${BUF_API_TOKEN} | buf registry login --username ${BUF_USER} --token-stdin
106+
# to logout
107+
buf registry logout
92108
```
93109

94110
#### Create buf lock files
95111
one-time-setup
96-
```bash
112+
```shell
97113
cd proto/dkit
98114
buf mod update
99115
cd proto/mkit
@@ -102,21 +118,21 @@ buf mod update
102118
This will pull deps into `$HOME/.cache/buf`
103119

104120
#### Create a Repository
105-
```bash
121+
```shell
106122
buf beta registry repository create buf.build/chintha/dkit --visibility private
107123
buf beta registry repository create buf.build/chintha/dkit --visibility public
108124

109125
buf beta registry repository create buf.build/chintha/mkit --visibility private
110126
```
111127

112128
#### List Modules
113-
```bash
129+
```shell
114130
buf beta registry repository list buf.build --page-size 100
115131
buf beta registry repository get buf.build/googleapis/googleapis
116132
```
117133

118134
#### Push the Module
119-
```bash
135+
```shell
120136
cd proto/dkit
121137
buf push
122138
cd proto/mkit
@@ -125,7 +141,7 @@ buf push
125141

126142
### Format
127143

128-
```bash
144+
```shell
129145
# FIXME buf don't have proto formatter yet
130146
prototool format -w proto;
131147
```
@@ -134,14 +150,14 @@ prototool format -w proto;
134150

135151
### grpcurl
136152

137-
```bash
153+
```shell
138154
# To use Buf-produced FileDescriptorSets with grpcurl on the fly:
139155
grpcurl -protoset <(buf build -o -) ...
140156
```
141157

142158
### ghz
143159

144-
```bash
160+
```shell
145161
# To use Buf-produced FileDescriptorSets with ghz on the fly:
146162
ghz --protoset <(buf build -o -) ...
147163
```

docs/images/goland-buf-watch.png

375 KB
Loading

0 commit comments

Comments
 (0)