-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix the issue of multiple package imports when generating triple files. #3052
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
13b53c3
修复生成triple时,多包引入问题
35cc9b9
Update tools/protoc-gen-go-triple/main.go
hs80 2b5f9be
Merge branch 'apache:develop' into develop
hs80 388ab9a
调整模板中导入库,保持原有格式
d55c5bf
修改循环的键名变量命名
208100a
Merge branch 'develop' into develop
hs80 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= | ||
| github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= | ||
| github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= | ||
| github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
| golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||
| golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
| google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= | ||
| google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= | ||
| google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= | ||
| google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import ( | |
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
| ) | ||
|
|
||
| import ( | ||
|
|
@@ -75,17 +76,55 @@ func main() { | |
| } | ||
|
|
||
| func genTriple(plugin *protogen.Plugin) error { | ||
| var errors []error | ||
|
|
||
| for _, file := range plugin.Files { | ||
| if !file.Generate { | ||
| continue | ||
| } | ||
| tripleGo, err := generator.ProcessProtoFile(file.Proto) | ||
| if err != nil { | ||
| return err | ||
|
|
||
| // 跳过无服务的proto文件 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use English |
||
| if len(file.Proto.GetService()) == 0 { | ||
| continue | ||
| } | ||
|
|
||
| filename := file.GeneratedFilenamePrefix + ".triple.go" | ||
| g := plugin.NewGeneratedFile(filename, file.GoImportPath) | ||
| return generator.GenTripleFile(g, tripleGo) | ||
| // Use the same import path as the pb.go file to ensure they're in the same package | ||
| // Extract the package name from the go_package option | ||
| goPackage := file.Proto.Options.GetGoPackage() | ||
| var importPath protogen.GoImportPath | ||
| if goPackage != "" { | ||
| parts := strings.Split(goPackage, ";") | ||
| importPath = protogen.GoImportPath(parts[0]) | ||
| } else { | ||
| importPath = file.GoImportPath | ||
| } | ||
| g := plugin.NewGeneratedFile(filename, importPath) | ||
|
hs80 marked this conversation as resolved.
Outdated
|
||
| // 导入dubbo基础库 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use English |
||
| g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/client").Ident("client")) | ||
| g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/common").Ident("common")) | ||
| g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/common/constant").Ident("constant")) | ||
| g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol").Ident("triple_protocol")) | ||
| g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/server").Ident("server")) | ||
|
hs80 marked this conversation as resolved.
|
||
| tripleGo, err := generator.ProcessProtoFile(g, file) | ||
| if err != nil { | ||
| errors = append(errors, fmt.Errorf("processing %s: %w", file.Desc.Path(), err)) | ||
| continue | ||
| } | ||
| // Ensure the generated file uses the exact Go package name computed by protoc-gen-go. | ||
| tripleGo.Package = string(file.GoPackageName) | ||
|
|
||
| err = generator.GenTripleFile(g, tripleGo) | ||
| if err != nil { | ||
| errors = append(errors, fmt.Errorf("generating %s: %w", filename, err)) | ||
| } | ||
| } | ||
| if len(errors) > 0 { | ||
| var errorMessages []string | ||
| for _, err := range errors { | ||
| errorMessages = append(errorMessages, err.Error()) | ||
| } | ||
| return fmt.Errorf("multiple errors occurred:\n%s", strings.Join(errorMessages, "\n")) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k_s 别取这种名字,你把这段代码粘贴到 chatgpt,可以咨询下,让它给你改个更合适的名字
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改