From d8e50eadaf224f79c1c127fcad2e1dfad4ecd689 Mon Sep 17 00:00:00 2001 From: duzhiruo1 <2275485503@qq.com> Date: Tue, 27 Aug 2024 21:31:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=20=E5=9C=A8h=E9=97=AD=E5=8C=85=E5=A4=96?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0reply=E8=B5=8B=E5=80=BC=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=EF=BC=88=E5=8E=9F=E5=9B=A0=EF=BC=9A=E8=80=83=E8=99=91=E5=88=B0?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E4=B8=AD=E9=97=B4=E4=BB=B6=E5=91=BD=E4=B8=AD?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=9A=84=E6=83=85=E5=86=B5=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=B8=80=E6=AD=A5=E5=9C=A8=E9=97=AD=E5=8C=85=E5=A4=96?= =?UTF-8?q?=E7=BB=99reply=E8=B5=8B=E5=80=BC=E7=9A=84=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E3=80=82=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transport/http/client.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/transport/http/client.go b/transport/http/client.go index 1d74542d522..1d553de3ce9 100644 --- a/transport/http/client.go +++ b/transport/http/client.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "reflect" "time" "github.com/go-kratos/kratos/v2/encoding" @@ -274,8 +275,20 @@ func (client *Client) invoke(ctx context.Context, req *http.Request, args interf if len(client.opts.middleware) > 0 { h = middleware.Chain(client.opts.middleware...)(h) } - _, err := h(ctx, args) - return err + + ret, err := h(ctx, args) + if err != nil { + return err + } + retValue := reflect.ValueOf(ret) + replyValue := reflect.ValueOf(reply) + if replyValue.Kind() == reflect.Ptr && !replyValue.IsNil() && retValue.Type() == replyValue.Elem().Type() { + replyValue.Elem().Set(retValue.Elem()) + } else { + reply = ret + } + + return nil } // Do send an HTTP request and decodes the body of response into target. From 2d73cd2ca6b9d11cb8735104a3725e91f3280b4b Mon Sep 17 00:00:00 2001 From: duzhiruo1 <2275485503@qq.com> Date: Tue, 27 Aug 2024 21:42:23 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"=20=E5=9C=A8h=E9=97=AD=E5=8C=85?= =?UTF-8?q?=E5=A4=96=E5=A2=9E=E5=8A=A0reply=E8=B5=8B=E5=80=BC=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=EF=BC=88=E5=8E=9F=E5=9B=A0=EF=BC=9A=E8=80=83=E8=99=91?= =?UTF-8?q?=E5=88=B0=E7=BC=93=E5=AD=98=E4=B8=AD=E9=97=B4=E4=BB=B6=E5=91=BD?= =?UTF-8?q?=E4=B8=AD=E7=BC=93=E5=AD=98=E7=9A=84=E6=83=85=E5=86=B5=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E6=AD=A5=E5=9C=A8=E9=97=AD=E5=8C=85?= =?UTF-8?q?=E5=A4=96=E7=BB=99reply=E8=B5=8B=E5=80=BC=E7=9A=84=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E3=80=82=EF=BC=89"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d8e50eadaf224f79c1c127fcad2e1dfad4ecd689. --- transport/http/client.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/transport/http/client.go b/transport/http/client.go index 1d553de3ce9..1d74542d522 100644 --- a/transport/http/client.go +++ b/transport/http/client.go @@ -7,7 +7,6 @@ import ( "fmt" "io" "net/http" - "reflect" "time" "github.com/go-kratos/kratos/v2/encoding" @@ -275,20 +274,8 @@ func (client *Client) invoke(ctx context.Context, req *http.Request, args interf if len(client.opts.middleware) > 0 { h = middleware.Chain(client.opts.middleware...)(h) } - - ret, err := h(ctx, args) - if err != nil { - return err - } - retValue := reflect.ValueOf(ret) - replyValue := reflect.ValueOf(reply) - if replyValue.Kind() == reflect.Ptr && !replyValue.IsNil() && retValue.Type() == replyValue.Elem().Type() { - replyValue.Elem().Set(retValue.Elem()) - } else { - reply = ret - } - - return nil + _, err := h(ctx, args) + return err } // Do send an HTTP request and decodes the body of response into target. From 03d6bc1ad70bb1b229b6dffcf9162a6e2c8016dc Mon Sep 17 00:00:00 2001 From: duzhiruo1 <2275485503@qq.com> Date: Tue, 27 Aug 2024 21:57:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix=20[transport=20client]=20<=E8=80=83?= =?UTF-8?q?=E8=99=91=E5=88=B0=E7=BC=93=E5=AD=98=E4=B8=AD=E9=97=B4=E4=BB=B6?= =?UTF-8?q?=E5=91=BD=E4=B8=AD=E7=BC=93=E5=AD=98=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=B8=80=E6=AD=A5=E5=9C=A8=E9=97=AD?= =?UTF-8?q?=E5=8C=85=E5=A4=96=E7=BB=99reply=E8=B5=8B=E5=80=BC=E7=9A=84?= =?UTF-8?q?=E6=93=8D=E4=BD=9C>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transport/http/client.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/transport/http/client.go b/transport/http/client.go index 1d74542d522..0b70be93065 100644 --- a/transport/http/client.go +++ b/transport/http/client.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "reflect" "time" "github.com/go-kratos/kratos/v2/encoding" @@ -274,8 +275,19 @@ func (client *Client) invoke(ctx context.Context, req *http.Request, args interf if len(client.opts.middleware) > 0 { h = middleware.Chain(client.opts.middleware...)(h) } - _, err := h(ctx, args) - return err + ret, err := h(ctx, args) + if err != nil { + return err + } + retValue := reflect.ValueOf(ret) + replyValue := reflect.ValueOf(reply) + if replyValue.Kind() == reflect.Ptr && !replyValue.IsNil() && retValue.Type() == replyValue.Elem().Type() { + replyValue.Elem().Set(retValue.Elem()) + } else { + reply = ret + } + + return nil } // Do send an HTTP request and decodes the body of response into target.