You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "hs80 (via GitHub)" <gi...@apache.org> on 2025/10/16 01:45:00 UTC

[PR] 修复生成triple时,多包引入问题 [dubbo-go]

hs80 opened a new pull request, #3052:
URL: https://github.com/apache/dubbo-go/pull/3052

   修改为使用protobuf库管理引用的库
   
   修改之后可以修复多proto文件引用造成的包调用问题,也可以避免类似dubbo的common库与自定义common库命名冲突等的问题


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#discussion_r2451815772


##########
tools/protoc-gen-go-triple/gen/generator/genTriple.go:
##########
@@ -59,21 +56,22 @@ func (g *Generator) generateToFile(filePath string, data []byte) error {
 	return util.GoFmtFile(filePath)
 }
 
-func ProcessProtoFile(file *descriptor.FileDescriptorProto) (TripleGo, error) {
+func ProcessProtoFile(g *protogen.GeneratedFile, f *protogen.File) (TripleGo, error) {
+	file := f.Proto
 	tripleGo := TripleGo{
 		Source:       file.GetName(),
 		ProtoPackage: file.GetPackage(),
 		Services:     make([]Service, 0),
 	}
-	for _, service := range file.GetService() {
+	for k_s, service := range file.GetService() {

Review Comment:
   k_s 别取这种名字,你把这段代码粘贴到 chatgpt,可以咨询下,让它给你改个更合适的名字



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3448486300

   @CAICAIIs check this
   先把 https://github.com/dubbogo/protoc-gen-go-triple 中的代码迁移到主仓库
   然后 check 一下这个 pr 合并功能


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "hs80 (via GitHub)" <gi...@apache.org>.
hs80 commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3430358841

   > 1. comment use English instead of Chinese
   > 2. import 块的格式不要修改
   
   1. 已修改
   2. 具体是指模板还是哪里?格式是指什么格式?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3430849299

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3475734415

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3430842223

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triples. [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3413571305

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl merged PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] 修复生成triple时,多包引入问题 [dubbo-go]

Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3413514871

   please update the pr title in english


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "hs80 (via GitHub)" <gi...@apache.org>.
hs80 commented on code in PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#discussion_r2453690345


##########
tools/protoc-gen-go-triple/gen/generator/genTriple.go:
##########
@@ -59,21 +56,22 @@ func (g *Generator) generateToFile(filePath string, data []byte) error {
 	return util.GoFmtFile(filePath)
 }
 
-func ProcessProtoFile(file *descriptor.FileDescriptorProto) (TripleGo, error) {
+func ProcessProtoFile(g *protogen.GeneratedFile, f *protogen.File) (TripleGo, error) {
+	file := f.Proto
 	tripleGo := TripleGo{
 		Source:       file.GetName(),
 		ProtoPackage: file.GetPackage(),
 		Services:     make([]Service, 0),
 	}
-	for _, service := range file.GetService() {
+	for k_s, service := range file.GetService() {

Review Comment:
   已修改



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] 修复生成triple时,多包引入问题 [dubbo-go]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#discussion_r2438003644


##########
tools/protoc-gen-go-triple/main.go:
##########
@@ -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文件
+		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)

Review Comment:
   protogen 已经在 file.GoImportPath 中解析了 go_package(若设置),这里再手动解析会引入边界情况(例如 go_package 仅有路径无分号、包含额外空格等)。建议直接使用 file.GoImportPath:g := plugin.NewGeneratedFile(filename, file.GoImportPath)。
   ```suggestion
   		// Use the import path as parsed by protogen to avoid edge cases.
   		g := plugin.NewGeneratedFile(filename, file.GoImportPath)
   ```



##########
tools/protoc-gen-go-triple/gen/generator/tripleTpl.go:
##########
@@ -140,16 +140,8 @@ const ImportTpl = `
 
 import (
 	"context"
-	{{if .IsStream}}"net/http"{{end}}
-)
-
-import (
 	"dubbo.apache.org/dubbo-go/v3"

Review Comment:
   模板的 ImportTpl 移除了 client、common、constant、triple_protocol、server 等 dubbo 依赖的 import,但生成代码仍会引用这些标识符。由于 GenTripleFile 直接将模板字符串写入文件(未使用 protogen 的自动 import 机制),main.go 中对 g.QualifiedGoIdent 的调用不会把这些包注入到 import 块,最终编译将出现未定义标识符错误。请恢复这些固定 import,或在模板中渲染一个基于收集到依赖的动态 import 列表。
   ```suggestion
   	"dubbo.apache.org/dubbo-go/v3"
   	"dubbo.apache.org/dubbo-go/v3/client"
   	"dubbo.apache.org/dubbo-go/v3/common"
   	"dubbo.apache.org/dubbo-go/v3/constant"
   	"dubbo.apache.org/dubbo-go/v3/protocol/triple"
   	"dubbo.apache.org/dubbo-go/v3/server"
   ```



##########
tools/protoc-gen-go-triple/main.go:
##########
@@ -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文件
+		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)
+		// 导入dubbo基础库
+		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"))

Review Comment:
   这些 QualifiedGoIdent 调用返回的引用字符串未被写入生成文件,且 GenTripleFile 直接写模板字符串,不会触发 protogen 的自动 import 注入。因此这些调用对最终 import 块没有任何效果。建议:要么恢复模板中的固定 import,要么改为使用 g.P 生成并实际输出这些引用,让 protogen 注入 import。
   ```suggestion
   		g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/server").Ident("server"))
   		// Output dummy references to trigger import injection
   		g.P("// Reference: ", g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/client").Ident("client")))
   		g.P("// Reference: ", g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/common").Ident("common")))
   		g.P("// Reference: ", g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/common/constant").Ident("constant")))
   		g.P("// Reference: ", g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol").Ident("triple_protocol")))
   		g.P("// Reference: ", g.QualifiedGoIdent(protogen.GoImportPath("dubbo.apache.org/dubbo-go/v3/server").Ident("server")))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] 修复生成triple时,多包引入问题 [dubbo-go]

Posted by "hs80 (via GitHub)" <gi...@apache.org>.
hs80 commented on code in PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#discussion_r2438012791


##########
tools/protoc-gen-go-triple/gen/generator/tripleTpl.go:
##########
@@ -140,16 +140,8 @@ const ImportTpl = `
 
 import (
 	"context"
-	{{if .IsStream}}"net/http"{{end}}
-)
-
-import (
 	"dubbo.apache.org/dubbo-go/v3"

Review Comment:
   这部分在main.go中已经增加使用如下生成方式:
   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"))



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] 修复生成triple时,多包引入问题 [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3408868556

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#discussion_r2450468599


##########
tools/protoc-gen-go-triple/main.go:
##########
@@ -75,17 +76,48 @@ 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文件
+		if len(file.Proto.GetService()) == 0 {
+			continue
 		}
+
 		filename := file.GeneratedFilenamePrefix + ".triple.go"
+		// 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
+		// Use the import path as parsed by protogen to avoid edge cases.
 		g := plugin.NewGeneratedFile(filename, file.GoImportPath)
-		return generator.GenTripleFile(g, tripleGo)
+		// 导入dubbo基础库

Review Comment:
   use English



##########
tools/protoc-gen-go-triple/main.go:
##########
@@ -75,17 +76,48 @@ 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文件

Review Comment:
   use English



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] 修复生成triple时,多包引入问题 [dubbo-go]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3408876113

   ## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3052?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 39.61%. Comparing base ([`60d1c2a`](https://app.codecov.io/gh/apache/dubbo-go/commit/60d1c2a949f0ee0da4be3fe09fb79d295491e040?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`13b53c3`](https://app.codecov.io/gh/apache/dubbo-go/commit/13b53c315d7ab273389fd700bd6e49deb8736824?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 642 commits behind head on develop.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff             @@
   ##           develop    #3052      +/-   ##
   ===========================================
   - Coverage    46.76%   39.61%   -7.16%     
   ===========================================
     Files          295      457     +162     
     Lines        17172    39075   +21903     
   ===========================================
   + Hits          8031    15479    +7448     
   - Misses        8287    22334   +14047     
   - Partials       854     1262     +408     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/dubbo-go/pull/3052?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] 修复生成triple时,多包引入问题 [dubbo-go]

Posted by "hs80 (via GitHub)" <gi...@apache.org>.
hs80 commented on code in PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#discussion_r2438033203


##########
tools/protoc-gen-go-triple/main.go:
##########
@@ -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文件
+		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)
+		// 导入dubbo基础库
+		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"))

Review Comment:
   g.QualifiedGoIdent方法内部会将包名和包路径做映射,然后放到内部变量保存,并标记此包是否已使用
   在生成代码时,protogen.GeneratedFile会将这些引用写入到生成文件的package下方



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3419647015

   1. comment use English instead of Chinese
   2. import 块的格式不要修改


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix the issue of multiple package imports when generating triple files. [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3052:
URL: https://github.com/apache/dubbo-go/pull/3052#issuecomment-3434737157

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3052&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3052&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3052&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3052)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org