Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize(hz): use relative path for grpc generated file #1022

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/hz/protobuf/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ func (plugin *Plugin) GenerateFile(gen *protogen.Plugin, f *protogen.File) error
if strings.HasPrefix(impt, plugin.Package) {
impt = impt[len(plugin.Package):]
}
// The file name must be the relative path, reference https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/compiler/plugin.proto#L122
if strings.HasPrefix(impt, "/") {
impt = impt[1:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the prefix “/” directly is not always right way to transfer absolute path to relative path?
An implicit premise is that the current work dir needs to be in "/"?

If there is something I missed please let me know🙏

}
f.GeneratedFilenamePrefix = filepath.Join(util.ImportToPath(impt, ""), util.BaseName(f.Proto.GetName(), ".proto"))
f.Generate = true
// if use third-party model, no model code is generated within the project
Expand Down