This is an automated email from the ASF dual-hosted git repository.

dmwangnima pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 750e9550c feat: update proto-gen-triple (#2528)
750e9550c is described below

commit 750e9550c41b7d8925d4631f8d833fe04ebdda39
Author: finalt <[email protected]>
AuthorDate: Sat Dec 2 10:30:04 2023 +0800

    feat: update proto-gen-triple (#2528)
    
    * update proto-gen-triple
    
    * update proto-gen-triple
    
    * add import
---
 .../gen/generator/tripleTpl.go                     | 33 ++++++++++++++--------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/cmd/protoc-gen-go-triple/gen/generator/tripleTpl.go 
b/cmd/protoc-gen-go-triple/gen/generator/tripleTpl.go
index 6f3d2d351..284a7b78a 100644
--- a/cmd/protoc-gen-go-triple/gen/generator/tripleTpl.go
+++ b/cmd/protoc-gen-go-triple/gen/generator/tripleTpl.go
@@ -154,7 +154,9 @@ import (
 )
 
 import (
+       "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/common/constant"
        "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
        "dubbo.apache.org/dubbo-go/v3/server"
@@ -210,22 +212,27 @@ type {{$s.ServiceName}} interface { {{- range $s.Methods}}
 `
 
 const InterfaceImplTpl = `{{$t := .}}{{range $s := .Services}}// 
New{{.ServiceName}} constructs a client for the {{$t.Package}}.{{.ServiceName}} 
service. 
-func New{{.ServiceName}}(cli *client.Client) ({{.ServiceName}}, error) {
-       if err := cli.Init(&{{.ServiceName}}_ClientInfo); err != nil {
+func New{{.ServiceName}}(cli *client.Client, opts ...client.ReferenceOption) 
({{.ServiceName}}, error) {
+       conn, err := cli.DialWithInfo("{{$t.ProtoPackage}}.{{.ServiceName}}", 
&{{.ServiceName}}_ClientInfo, opts...)
+       if err != nil {
                return nil, err
        }
        return &{{.ServiceName}}Impl{
-               cli: cli,
+               conn: conn,
        }, nil
 }
 
+func SetConsumerService(srv common.RPCService) {
+       dubbo.SetConsumerServiceWithInfo(srv,&{{.ServiceName}}_ClientInfo)
+}
+
 // {{.ServiceName}}Impl implements {{.ServiceName}}.
 type {{.ServiceName}}Impl struct {
-       cli *client.Client
+       conn *client.Connection
 }
 {{range .Methods}}{{if .StreamsRequest}}{{if .StreamsReturn}}
 func (c *{{$s.ServiceName}}Impl) {{.MethodName}}(ctx context.Context, opts 
...client.CallOption) ({{$s.ServiceName}}_{{.MethodName}}Client, error) {
-       stream, err := c.cli.CallBidiStream(ctx, 
"{{$t.ProtoPackage}}.{{$s.ServiceName}}", "{{.MethodName}}", opts...)
+       stream, err := c.conn.CallBidiStream(ctx, "{{.MethodName}}", opts...)
        if err != nil {
                return nil, err
        }
@@ -234,7 +241,7 @@ func (c *{{$s.ServiceName}}Impl) {{.MethodName}}(ctx 
context.Context, opts ...cl
 }
 {{else}}
 func (c *{{$s.ServiceName}}Impl) {{.MethodName}}(ctx context.Context, opts 
...client.CallOption) ({{$s.ServiceName}}_{{.MethodName}}Client, error) {
-       stream, err := c.cli.CallClientStream(ctx, 
"{{$t.ProtoPackage}}.{{$s.ServiceName}}", "{{.MethodName}}", opts...)
+       stream, err := c.conn.CallClientStream(ctx, "{{.MethodName}}", opts...)
        if err != nil {
                return nil, err
        }
@@ -243,7 +250,7 @@ func (c *{{$s.ServiceName}}Impl) {{.MethodName}}(ctx 
context.Context, opts ...cl
 }
 {{end}}{{else}}{{if .StreamsReturn}}
 func (c *{{$s.ServiceName}}Impl) {{.MethodName}}(ctx context.Context, req 
*proto.{{.RequestType}}, opts ...client.CallOption) 
({{$s.ServiceName}}_{{.MethodName}}Client, error) {
-       stream, err := c.cli.CallServerStream(ctx, req, 
"{{$t.ProtoPackage}}.{{$s.ServiceName}}", "{{.MethodName}}", opts...)
+       stream, err := c.conn.CallServerStream(ctx, req, "{{.MethodName}}", 
opts...)
        if err != nil {
                return nil, err
        }
@@ -253,7 +260,7 @@ func (c *{{$s.ServiceName}}Impl) {{.MethodName}}(ctx 
context.Context, req *proto
 {{else}}
 func (c *{{$s.ServiceName}}Impl) {{.MethodName}}(ctx context.Context, req 
*proto.{{.RequestType}}, opts ...client.CallOption) (*proto.{{.ReturnType}}, 
error) {
        resp := new(proto.{{.ReturnType}})
-       if err := c.cli.CallUnary(ctx, req, resp, 
"{{$t.ProtoPackage}}.{{$s.ServiceName}}", "{{.MethodName}}", opts...); err != 
nil {
+       if err := c.conn.CallUnary(ctx, []interface{}{req}, resp, 
"{{.MethodName}}", opts...); err != nil {
                return nil, err
        }
        return resp, nil
@@ -356,9 +363,9 @@ func (cli *{{$s.ServiceName}}{{.MethodName}}Client) Conn() 
(triple_protocol.Stre
 const MethodInfoTpl = `{{$t := .}}{{range $i, $s := .Services}}var 
{{.ServiceName}}_ClientInfo = client.ClientInfo{
        InterfaceName: "{{$t.Package}}.{{.ServiceName}}",
        MethodNames:   []string{ {{- range $j, $m := 
.Methods}}"{{.MethodName}}"{{if last $j (len $s.Methods)}}{{else}},{{end}}{{end 
-}} },
-       ClientInjectFunc: func(dubboCliRaw interface{}, cli *client.Client) {
-               dubboCli := dubboCliRaw.({{$s.ServiceName}}Impl)
-               dubboCli.cli = cli
+       ConnectionInjectFunc: func(dubboCliRaw interface{}, conn 
*client.Connection) {
+               dubboCli := dubboCliRaw.(*{{$s.ServiceName}}Impl)
+               dubboCli.conn = conn
        },
 }{{end}}
 
@@ -371,6 +378,10 @@ type {{.ServiceName}}Handler interface { {{- range 
$s.Methods}}
 
 func Register{{.ServiceName}}Handler(srv *server.Server, hdlr 
{{.ServiceName}}Handler, opts ...server.ServiceOption) error {
        return srv.Register(hdlr, &{{.ServiceName}}_ServiceInfo, opts...)
+}
+
+func SetProviderService(srv common.RPCService)  {
+       dubbo.SetProviderServiceWithInfo(srv,&{{.ServiceName}}_ServiceInfo)
 }{{end}}
 `
 

Reply via email to