diff --git a/cmd/hz/protobuf/plugin.go b/cmd/hz/protobuf/plugin.go index 189aedd6f..eb812894a 100644 --- a/cmd/hz/protobuf/plugin.go +++ b/cmd/hz/protobuf/plugin.go @@ -362,7 +362,11 @@ func (plugin *Plugin) GenerateFiles(pluginPb *protogen.Plugin) error { func (plugin *Plugin) GenerateFile(gen *protogen.Plugin, f *protogen.File) error { impt := string(f.GoImportPath) if strings.HasPrefix(impt, plugin.Package) { - impt = impt[len(plugin.Package)+1:] + 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:] } f.GeneratedFilenamePrefix = filepath.Join(util.ImportToPath(impt, ""), util.BaseName(f.Proto.GetName(), ".proto")) f.Generate = true