diff --git a/transport/grpc/client.go b/transport/grpc/client.go index c6221a8a6..b766fbe70 100644 --- a/transport/grpc/client.go +++ b/transport/grpc/client.go @@ -101,7 +101,7 @@ func dial(ctx context.Context, insecure bool, opts ...ClientOption) (*grpc.Clien // UnaryClientInterceptor retruns a unary client interceptor. func UnaryClientInterceptor(m middleware.Middleware) grpc.UnaryClientInterceptor { return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { - ctx = transport.NewContext(ctx, transport.Transport{Kind: "gRPC"}) + ctx = transport.NewContext(ctx, transport.Transport{Kind: transport.KindGRPC}) ctx = NewClientContext(ctx, ClientInfo{FullMethod: method}) h := func(ctx context.Context, req interface{}) (interface{}, error) { return reply, invoker(ctx, method, req, reply, cc, opts...) diff --git a/transport/grpc/server.go b/transport/grpc/server.go index ce118660a..51b301d89 100644 --- a/transport/grpc/server.go +++ b/transport/grpc/server.go @@ -146,7 +146,7 @@ func UnaryTimeoutInterceptor(timeout time.Duration) grpc.UnaryServerInterceptor // UnaryServerInterceptor returns a unary server interceptor. func UnaryServerInterceptor(m middleware.Middleware) grpc.UnaryServerInterceptor { return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - ctx = transport.NewContext(ctx, transport.Transport{Kind: "gRPC"}) + ctx = transport.NewContext(ctx, transport.Transport{Kind: transport.KindGRPC}) ctx = NewServerContext(ctx, ServerInfo{Server: info.Server, FullMethod: info.FullMethod}) h := func(ctx context.Context, req interface{}) (interface{}, error) { return handler(ctx, req) diff --git a/transport/http/client.go b/transport/http/client.go index 42cae72bb..38e0fb4af 100644 --- a/transport/http/client.go +++ b/transport/http/client.go @@ -90,7 +90,7 @@ func (t *baseTransport) RoundTrip(req *http.Request) (*http.Response, error) { if t.userAgent != "" && req.Header.Get("User-Agent") == "" { req.Header.Set("User-Agent", t.userAgent) } - ctx := transport.NewContext(req.Context(), transport.Transport{Kind: "HTTP"}) + ctx := transport.NewContext(req.Context(), transport.Transport{Kind: transport.KindHTTP}) ctx = NewClientContext(ctx, ClientInfo{Request: req}) ctx, cancel := context.WithTimeout(ctx, t.timeout) defer cancel() diff --git a/transport/http/server.go b/transport/http/server.go index 4d423d62a..b26bf6015 100644 --- a/transport/http/server.go +++ b/transport/http/server.go @@ -96,7 +96,7 @@ func (s *Server) HandleFunc(path string, h http.HandlerFunc) { func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request) { ctx, cancel := context.WithTimeout(req.Context(), s.timeout) defer cancel() - ctx = transport.NewContext(ctx, transport.Transport{Kind: "HTTP"}) + ctx = transport.NewContext(ctx, transport.Transport{Kind: transport.KindHTTP}) ctx = NewServerContext(ctx, ServerInfo{Request: req, Response: res}) s.router.ServeHTTP(res, req.WithContext(ctx)) } diff --git a/transport/transport.go b/transport/transport.go index 64e74734a..91ba7d48d 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -17,9 +17,18 @@ type Server interface { // Transport is transport context value. type Transport struct { - Kind string + Kind Kind } +// Kind defines the type of Transport +type Kind string + +// Defines a set of transport kind +const ( + KindGRPC Kind = "gRPC" + KindHTTP Kind = "HTTP" +) + type transportKey struct{} // NewContext returns a new Context that carries value.