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

+5
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

+14-1
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

+3
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

+8-14
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

+1-1
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

+4-2
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

+1-1
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

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/advanced/buf.md

+35-19
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

docs/images/goland-proto-import.png

725 KB
Loading

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ require (
2727
github.com/xmlking/toolkit/logger v0.2.4
2828
github.com/xmlking/toolkit/telemetry v0.2.4
2929
github.com/xmlking/toolkit/xds v0.2.4
30-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.30.0
31-
go.opentelemetry.io/otel v1.6.0
30+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.31.0
31+
go.opentelemetry.io/otel v1.6.1
3232
go.opentelemetry.io/otel/metric v0.26.0
33-
go.opentelemetry.io/otel/trace v1.6.0
33+
go.opentelemetry.io/otel/trace v1.6.1
3434
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
3535
google.golang.org/grpc v1.45.0
3636
google.golang.org/protobuf v1.28.0

go.sum

+6-8
Original file line numberDiff line numberDiff line change
@@ -701,17 +701,16 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
701701
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
702702
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
703703
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
704-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.30.0 h1:3rCOYB0P/u0/MXyLGuRuc/VdBsQuxKgj/dvIpVI0lS4=
705-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.30.0/go.mod h1:L02XUVEqBFpJPJmaKLi5sXFiMwzd152PNMsCThH7dHc=
704+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.31.0 h1:li8u9OSMvLau7rMs8bmiL82OazG6MAkwPz2i6eS8TBQ=
705+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.31.0/go.mod h1:SY9qHHUES6W3oZnO1H2W8NvsSovIoXRg/A1AH9px8+I=
706706
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.24.0 h1:qW6j1kJU24yo2xIu16Py4m4AXn1dd+s2uKllGnTFAm0=
707707
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.24.0/go.mod h1:7W3JSDYTtH3qKKHrS1fMiwLtK7iZFLPq1+7htfspX/E=
708708
go.opentelemetry.io/otel v1.0.0-RC3/go.mod h1:Ka5j3ua8tZs4Rkq4Ex3hwgBgOchyPVq5S6P2lz//nKQ=
709709
go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg=
710710
go.opentelemetry.io/otel v1.0.1/go.mod h1:OPEOD4jIT2SlZPMmwT6FqZz2C0ZNdQqiWcoK6M0SNFU=
711711
go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs=
712-
go.opentelemetry.io/otel v1.5.0/go.mod h1:Jm/m+rNp/z0eqJc74H7LPwQ3G87qkU/AnnAydAjSAHk=
713-
go.opentelemetry.io/otel v1.6.0 h1:YV6GkGe/Ag2PKsm4rjlqdSNs0w0A5ZzxeGkxhx1T+t4=
714-
go.opentelemetry.io/otel v1.6.0/go.mod h1:bfJD2DZVw0LBxghOTlgnlI0CV3hLDu9XF/QKOUXMTQQ=
712+
go.opentelemetry.io/otel v1.6.1 h1:6r1YrcTenBvYa1x491d0GGpTVBsNECmrc/K6b+zDeis=
713+
go.opentelemetry.io/otel v1.6.1/go.mod h1:blzUabWHkX6LJewxvadmzafgh/wnvBSDBdOuwkAtrWQ=
715714
go.opentelemetry.io/otel/exporters/prometheus v0.26.0 h1:qsF1KFEE+dIRoQN0M0D/A9mdhu0TqQCNAzl0o1S2CIM=
716715
go.opentelemetry.io/otel/exporters/prometheus v0.26.0/go.mod h1:0/uJZI7H2y0FgMVCgCWdPzZpxPx3X3F5uInY32I9foI=
717716
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.26.0 h1:w7fF+cx3zdxURlLuVhzuYt6BT9COyecNfYYhtHXZoDc=
@@ -735,9 +734,8 @@ go.opentelemetry.io/otel/trace v1.0.0-RC3/go.mod h1:VUt2TUYd8S2/ZRX09ZDFZQwn2Rqf
735734
go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH814St6o6ajzIs=
736735
go.opentelemetry.io/otel/trace v1.0.1/go.mod h1:5g4i4fKLaX2BQpSBsxw8YYcgKpMMSW3x7ZTuYBr3sUk=
737736
go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk=
738-
go.opentelemetry.io/otel/trace v1.5.0/go.mod h1:sq55kfhjXYr1zVSyexg0w1mpa03AYXR5eyTkB9NPPdE=
739-
go.opentelemetry.io/otel/trace v1.6.0 h1:NDzPermp9ISkhxIaJXjBTi2O60xOSHDHP/EezjOL2wo=
740-
go.opentelemetry.io/otel/trace v1.6.0/go.mod h1:qs7BrU5cZ8dXQHBGxHMOxwME/27YH2qEp4/+tZLLwJE=
737+
go.opentelemetry.io/otel/trace v1.6.1 h1:f8c93l5tboBYZna1nWk0W9DYyMzJXDWdZcJZ0Kb400U=
738+
go.opentelemetry.io/otel/trace v1.6.1/go.mod h1:RkFRM1m0puWIq10oxImnGEduNBzxiN7TXluRBtE+5j0=
741739
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
742740
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
743741
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=

go.work

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use (
1313

1414
//replace github.com/xmlking/toolkit/telemetry => ../toolkit/telemetry
1515

16-
//replace github.com/xmlking/toolkit => github.com/xmlking/toolkit v0.1.2-0.20210125025404-51fc2d71fb2d
17-
1816
//replace github.com/xmlking/toolkit/xds => ../toolkit/xds
1917

20-
replace github.com/xmlking/toolkit/xds => github.com/xmlking/toolkit/xds v0.2.5-0.20220327073200-7a0bd5cf638b
18+
replace github.com/xmlking/toolkit/xds => github.com/xmlking/toolkit/xds v0.2.5-0.20220329222226-895ec254c86c
19+
20+
replace github.com/xmlking/toolkit => github.com/xmlking/toolkit v0.2.5-0.20220329222226-895ec254c86c
21+

go.work.sum

-20
This file was deleted.

0 commit comments

Comments
 (0)