diff --git a/auth/jwt/transport.go b/auth/jwt/transport.go index 6d02f7d..7be7db4 100644 --- a/auth/jwt/transport.go +++ b/auth/jwt/transport.go @@ -44,10 +44,10 @@ // ToGRPCContext moves JWT token from grpc metadata to context. Particularly // userful for servers. -func ToGRPCContext() grpc.RequestFunc { - return func(ctx context.Context, md *metadata.MD) context.Context { +func ToGRPCContext() grpc.ServerRequestFunc { + return func(ctx context.Context, md metadata.MD) context.Context { // capital "Key" is illegal in HTTP/2. - authHeader, ok := (*md)["authorization"] + authHeader, ok := md["authorization"] if !ok { return ctx } @@ -63,7 +63,7 @@ // FromGRPCContext moves JWT token from context to grpc metadata. Particularly // useful for clients. -func FromGRPCContext() grpc.RequestFunc { +func FromGRPCContext() grpc.ClientRequestFunc { return func(ctx context.Context, md *metadata.MD) context.Context { token, ok := ctx.Value(JWTTokenContextKey).(string) if ok { diff --git a/auth/jwt/transport_test.go b/auth/jwt/transport_test.go index 8b8922a..b04d76f 100644 --- a/auth/jwt/transport_test.go +++ b/auth/jwt/transport_test.go @@ -69,7 +69,7 @@ reqFunc := ToGRPCContext() // No Authorization header is passed - ctx := reqFunc(context.Background(), &md) + ctx := reqFunc(context.Background(), md) token := ctx.Value(JWTTokenContextKey) if token != nil { t.Error("Context should not contain a JWT Token") @@ -77,7 +77,7 @@ // Invalid Authorization header is passed md["authorization"] = []string{fmt.Sprintf("%s", signedKey)} - ctx = reqFunc(context.Background(), &md) + ctx = reqFunc(context.Background(), md) token = ctx.Value(JWTTokenContextKey) if token != nil { t.Error("Context should not contain a JWT Token") @@ -85,7 +85,7 @@ // Authorization header is correct md["authorization"] = []string{fmt.Sprintf("Bearer %s", signedKey)} - ctx = reqFunc(context.Background(), &md) + ctx = reqFunc(context.Background(), md) token, ok := ctx.Value(JWTTokenContextKey).(string) if !ok { t.Fatal("JWT Token not passed to context correctly") diff --git a/tracing/opentracing/grpc.go b/tracing/opentracing/grpc.go index 56eb143..fa45440 100644 --- a/tracing/opentracing/grpc.go +++ b/tracing/opentracing/grpc.go @@ -32,10 +32,10 @@ // `operationName` accordingly. If no trace could be found in `req`, the Span // will be a trace root. The Span is incorporated in the returned Context and // can be retrieved with opentracing.SpanFromContext(ctx). -func FromGRPCRequest(tracer opentracing.Tracer, operationName string, logger log.Logger) func(ctx context.Context, md *metadata.MD) context.Context { - return func(ctx context.Context, md *metadata.MD) context.Context { +func FromGRPCRequest(tracer opentracing.Tracer, operationName string, logger log.Logger) func(ctx context.Context, md metadata.MD) context.Context { + return func(ctx context.Context, md metadata.MD) context.Context { var span opentracing.Span - wireContext, err := tracer.Extract(opentracing.TextMap, metadataReaderWriter{md}) + wireContext, err := tracer.Extract(opentracing.TextMap, metadataReaderWriter{&md}) if err != nil && err != opentracing.ErrSpanContextNotFound { logger.Log("err", err) } diff --git a/tracing/opentracing/grpc_test.go b/tracing/opentracing/grpc_test.go index 96a834f..3d07a14 100644 --- a/tracing/opentracing/grpc_test.go +++ b/tracing/opentracing/grpc_test.go @@ -41,7 +41,7 @@ // Use FromGRPCRequest to verify that we can join with the trace given MD. fromGRPCFunc := kitot.FromGRPCRequest(tracer, "joined", logger) - joinCtx := fromGRPCFunc(afterCtx, &md) + joinCtx := fromGRPCFunc(afterCtx, md) joinedSpan := opentracing.SpanFromContext(joinCtx).(*mocktracer.MockSpan) joinedContext := joinedSpan.Context().(mocktracer.MockSpanContext)