cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.04k stars 491 forks source link

生成 model 文件路径不符合预期 #1154

Open sscui opened 1 month ago

sscui commented 1 month ago

Describe the bug

我在 proto 文件中定义了 go_packages,然后我使用 hz update 去生成相应的model文件,结果生成的文件路径与我在 proto 定义的文件路径不符

Replay 我的项目名为 hello

  1. 创建 idl/hello/hello.proto 文件
  2. 将 demo 中的文件内容复制进去
  3. 编辑 go_packages 路径(只要路径中包含 “hello”子字串即可,此处假设为 hertz/hello1 )
  4. 运行 hz new -module hello -I idl -idl idl/hello/hello.proto
  5. hello.pb.go 预期应该生成在 biz/model 下的 hertz/hello1 文件夹。但是实际上却是在 biz/model 的根目录下
  6. 编辑 go_packages 路径更新为 hertz/hell
  7. 运行 hz update -I idl -idl idl/hello/hello.proto
  8. 实际运行结果如预期:hello.pb.go 生成在 biz/model 下的 hertz/hell 文件夹

Note 只要我的go_packages 路径中包含或者等于 hello,这个实际生成的 pb 文件路径就会有问题

Hertz version:

hz -version
hz version v0.9.0
3DRX commented 1 month ago

我在 #1155 试着修复了一下这个问题,不清楚是否是这个功能设计时的本意,请 review。

Skyenought commented 1 month ago

你好, 这是我使用的 proto 文件

syntax = "proto3";

package hello;

option go_package = "hertz/hello";

import "api.proto";

message HelloReq {
  string Name = 1[(api.query)="name"];
}

message HelloResp {
  string RespBody = 1;
}

service HelloService {
  rpc Method1(HelloReq) returns(HelloResp) {
    option (api.get) = "/hello";
  }
}

依据 go_package 定义, 它应该生成在 biz/model/hello/hello.pb.go 我并没有复现出你的问题.

或者你可以提供你的 proto 用于我们来确定问题的来源

sscui commented 1 month ago

option go_package = "hertz/hello"; 不应该是 biz/model/hertz/hello/hello.pb.go 吗?实际上它的生成文件是在 biz/model/hello.pb.go 关键点可能是 hz new -module hello -I idl -idl idl/hello/hello.proto 的 module 是 hello,而不是文档中的 example.com/m。这导致 module 是我 go_package 的一个子串

Skyenought commented 1 month ago

ok, 确实是存在相应的问题的, 我来 cr 一下

Skyenought commented 1 month ago

但是 预期生成路径应该是 biz/model + go_package 中定义的路径, 所以说 biz/model/hello/hello.pb.go 这个路径是没有错误的