feat: add http transport interface (#1533)

feat: add http transport interface
pull/1535/head
longxboy 3 years ago committed by GitHub
parent a99659052a
commit 056812e4b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      middleware/tracing/span.go
  2. 9
      transport/http/transport.go

@ -26,7 +26,7 @@ func setClientSpan(ctx context.Context, span trace.Span, m interface{}) {
operation = tr.Operation() operation = tr.Operation()
rpcKind = tr.Kind().String() rpcKind = tr.Kind().String()
if tr.Kind() == transport.KindHTTP { if tr.Kind() == transport.KindHTTP {
if ht, ok := tr.(*http.Transport); ok { if ht, ok := tr.(http.Transporter); ok {
method := ht.Request().Method method := ht.Request().Method
route := ht.PathTemplate() route := ht.PathTemplate()
path := ht.Request().URL.Path path := ht.Request().URL.Path
@ -61,7 +61,7 @@ func setServerSpan(ctx context.Context, span trace.Span, m interface{}) {
operation = tr.Operation() operation = tr.Operation()
rpcKind = tr.Kind().String() rpcKind = tr.Kind().String()
if tr.Kind() == transport.KindHTTP { if tr.Kind() == transport.KindHTTP {
if ht, ok := tr.(*http.Transport); ok { if ht, ok := tr.(http.Transporter); ok {
method := ht.Request().Method method := ht.Request().Method
route := ht.PathTemplate() route := ht.PathTemplate()
path := ht.Request().URL.Path path := ht.Request().URL.Path

@ -7,7 +7,14 @@ import (
"github.com/go-kratos/kratos/v2/transport" "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. // Transport is an HTTP transport.
type Transport struct { type Transport struct {

Loading…
Cancel
Save