feat: google proto

This commit is contained in:
zzw
2026-08-06 17:00:28 +08:00
parent 1d375324f3
commit beaf8b911a
6 changed files with 430 additions and 14 deletions
+16 -8
View File
@@ -335,9 +335,20 @@ func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
protoc --include_imports --proto_path=proto --descriptor_set_out=../bff/etc/order.pb order.proto
```
### 9. 在 BFF 配 Upstream + Mapping
### 9. 在 BFF 配 UpstreamHTTP 路由写在 proto
编辑 `bff/etc/bff.yaml`,在 **Upstreams** 增加一段
在对应 RPC 上声明 `google.api.http`(需 `import "google/api/annotations.proto";`):
```protobuf
rpc Ping(Request) returns (Response) {
option (google.api.http) = {
post: "/admin/v3/order/ping"
body: "*"
};
}
```
编辑 `bff/etc/bff.yaml`,在 **Upstreams** 增加一段(不必写 Mappingsgateway 会从 ProtoSet 里的 http option 注册路由):
```yaml
- Name: order
@@ -346,18 +357,14 @@ protoc --include_imports --proto_path=proto --descriptor_set_out=../bff/etc/orde
Timeout: 5000
ProtoSets:
- etc/order.pb
Mappings:
- Method: post
Path: /admin/v3/order/ping
RpcPath: order.Order/Ping
```
### 编写业务须知
只改业务逻辑(`internal/logic/`)不必跑 goctl。
`proto/order.proto`(新增/改名 RPC、改字段等)后,按文末「三条命令何时用」处理;
`proto/order.proto`(新增/改名 RPC、改字段、改 http option 等)后,按文末「三条命令何时用」处理;
若 HTTP 路径有变,再改第 9 步的 Mapping
若 HTTP 路径有变,改 proto 里的 `google.api.http` 后重新跑命令 ② 生成 ProtoSet
---
@@ -381,6 +388,7 @@ protoc -I. -I../pkg/third_party --descriptor_set_out=../bff/etc/order.pb --inclu
- 增删改 **字段**BFF gateway 编解码需要)
- 增删 **RPC**
-**google.api.http** 路由
### 命令 ③:goctl 生成/更新脚手架