From 056812e4b2654778b7cf44d9d421405c76708252 Mon Sep 17 00:00:00 2001 From: longxboy Date: Fri, 8 Oct 2021 11:10:21 +0800 Subject: [PATCH] feat: add http transport interface (#1533) feat: add http transport interface --- middleware/tracing/span.go | 4 ++-- transport/http/transport.go | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/middleware/tracing/span.go b/middleware/tracing/span.go index 81334872a..b60433b6b 100644 --- a/middleware/tracing/span.go +++ b/middleware/tracing/span.go @@ -26,7 +26,7 @@ func setClientSpan(ctx context.Context, span trace.Span, m interface{}) { operation = tr.Operation() rpcKind = tr.Kind().String() if tr.Kind() == transport.KindHTTP { - if ht, ok := tr.(*http.Transport); ok { + if ht, ok := tr.(http.Transporter); ok { method := ht.Request().Method route := ht.PathTemplate() path := ht.Request().URL.Path @@ -61,7 +61,7 @@ func setServerSpan(ctx context.Context, span trace.Span, m interface{}) { operation = tr.Operation() rpcKind = tr.Kind().String() if tr.Kind() == transport.KindHTTP { - if ht, ok := tr.(*http.Transport); ok { + if ht, ok := tr.(http.Transporter); ok { method := ht.Request().Method route := ht.PathTemplate() path := ht.Request().URL.Path diff --git a/transport/http/transport.go b/transport/http/transport.go index fad5f6f7e..c377b5ad9 100644 --- a/transport/http/transport.go +++ b/transport/http/transport.go @@ -7,7 +7,14 @@ import ( "github.com/go-kratos/kratos/v2/transport" ) -var _ transport.Transporter = &Transport{} +var _ Transporter = &Transport{} + +// Transporter is http Transporter +type Transporter interface { + transport.Transporter + Request() *http.Request + PathTemplate() string +} // Transport is an HTTP transport. type Transport struct {