feat: proto tips

main
sudo pacman -Syu 2023-06-11 18:02:42 +07:00
parent c2612f89f4
commit 3b45c235a7
2 changed files with 33 additions and 8 deletions

View File

@ -63,7 +63,7 @@
<li><code>buf.yaml</code></li> <li><code>buf.yaml</code></li>
<li><code>buf.gen.yaml</code></li> <li><code>buf.gen.yaml</code></li>
</ul> </ul>
<p>FYI, the libs version I use:</p> <p>FYI, I use:</p>
<ul> <ul>
<li> <li>
<a <a
@ -113,11 +113,11 @@
<div class="highlight highlight-source-yaml"> <div class="highlight highlight-source-yaml">
<pre><span class="pl-ent">version</span>: <span class="pl-c1">v1</span> <pre><span class="pl-ent">version</span>: <span class="pl-c1">v1</span>
<span class="pl-ent">plugins</span>: <span class="pl-ent">plugins</span>:
- <span class="pl-ent">plugin</span>: <span class="pl-s">buf.build/grpc/go:v1.2.0</span> - <span class="pl-ent">plugin</span>: <span class="pl-s">buf.build/grpc/go:v1.3.0</span>
<span class="pl-ent">out</span>: <span class="pl-s">pkg</span> <span class="pl-ent">out</span>: <span class="pl-s">pkg</span>
- <span class="pl-ent">plugin</span>: <span class="pl-s">buf.build/protocolbuffers/go:v1.28.1</span> - <span class="pl-ent">plugin</span>: <span class="pl-s">buf.build/protocolbuffers/go:v1.30.0</span>
<span class="pl-ent">out</span>: <span class="pl-s">pkg</span> <span class="pl-ent">out</span>: <span class="pl-s">pkg</span>
- <span class="pl-ent">plugin</span>: <span class="pl-s">buf.build/bufbuild/validate-go:v0.9.0</span> - <span class="pl-ent">plugin</span>: <span class="pl-s">buf.build/bufbuild/validate-go:v1.0.1</span>
<span class="pl-ent">out</span>: <span class="pl-s">pkg</span> <span class="pl-ent">out</span>: <span class="pl-s">pkg</span>
<span class="pl-ent">opt</span>: <span class="pl-ent">opt</span>:
- <span class="pl-s">lang=go</span> - <span class="pl-s">lang=go</span>
@ -210,6 +210,22 @@
compatibility. compatibility.
</li> </li>
</ul> </ul>
<h1>
<a id="user-content-tips" class="anchor" aria-hidden="true" href="#tips"
><span aria-hidden="true" class="octicon octicon-link"></span></a
>Tips
</h1>
<p>Some experience I got after writing proto files for a living:</p>
<ul>
<li>
Ignore DRY (Do not Repeat Yourself) when handling proto, don't split
proto into many files. Trust me, it saves you from wasting time to debug
how to import Go after generated. Because proto import and Go import is
<a href="https://github.com/golang/protobuf/issues/895">2</a> different
things. If someone already have split proto files, you should use
<code>sed</code> to fix the damn things.
</li>
</ul>
<h2> <h2>
<a <a
id="user-content-thanks" id="user-content-thanks"

View File

@ -8,7 +8,7 @@ We need 3 files:
- `buf.yaml` - `buf.yaml`
- `buf.gen.yaml` - `buf.gen.yaml`
FYI, the libs version I use: FYI, I use:
- [grpc-ecosystem/grpc-gateway v1.16.0](https://github.com/grpc-ecosystem/grpc-gateway/releases/tag/v1.16.0) - [grpc-ecosystem/grpc-gateway v1.16.0](https://github.com/grpc-ecosystem/grpc-gateway/releases/tag/v1.16.0)
- [bufbuild/protoc-gen-validate](github.com/bufbuild/protoc-gen-validate) - [bufbuild/protoc-gen-validate](github.com/bufbuild/protoc-gen-validate)
@ -50,11 +50,11 @@ lint:
```yaml ```yaml
version: v1 version: v1
plugins: plugins:
- plugin: buf.build/grpc/go:v1.2.0 - plugin: buf.build/grpc/go:v1.3.0
out: pkg out: pkg
- plugin: buf.build/protocolbuffers/go:v1.28.1 - plugin: buf.build/protocolbuffers/go:v1.30.0
out: pkg out: pkg
- plugin: buf.build/bufbuild/validate-go:v0.9.0 - plugin: buf.build/bufbuild/validate-go:v1.0.1
out: pkg out: pkg
opt: opt:
- lang=go - lang=go
@ -118,6 +118,15 @@ If you are not migrate but start from scratch:
- Add `buf lint` to make sure your proto is good. - Add `buf lint` to make sure your proto is good.
- Add `buf breaking --against "https://your-grpc-repo-goes-here.git"` to make sure each time you update proto, you don't break backward compatibility. - Add `buf breaking --against "https://your-grpc-repo-goes-here.git"` to make sure each time you update proto, you don't break backward compatibility.
# Tips
Some experience I got after writing proto files for a living:
- Ignore DRY (Do not Repeat Yourself) when handling proto, don't split proto into many files.
Trust me, it saves you from wasting time to debug how to import Go after generated.
Because proto import and Go import is [2](https://github.com/golang/protobuf/issues/895) different things.
If someone already have split proto files, you should use `sed` to fix the damn things.
## Thanks ## Thanks
- [uber/prototool](https://github.com/uber/prototool) - [uber/prototool](https://github.com/uber/prototool)