diff --git a/auth/jwt/transport.go b/auth/jwt/transport.go index 7be7db4..bf41e63 100644 --- a/auth/jwt/transport.go +++ b/auth/jwt/transport.go @@ -17,9 +17,9 @@ bearerFormat string = "Bearer %s" ) -// ToHTTPContext moves JWT token from request header to context. Particularly +// HTTPToContext moves JWT token from request header to context. Particularly // useful for servers. -func ToHTTPContext() http.RequestFunc { +func HTTPToContext() http.RequestFunc { return func(ctx context.Context, r *stdhttp.Request) context.Context { token, ok := extractTokenFromAuthHeader(r.Header.Get("Authorization")) if !ok { @@ -30,9 +30,9 @@ } } -// FromHTTPContext moves JWT token from context to request header. Particularly +// ContextToHTTP moves JWT token from context to request header. Particularly // useful for clients. -func FromHTTPContext() http.RequestFunc { +func ContextToHTTP() http.RequestFunc { return func(ctx context.Context, r *stdhttp.Request) context.Context { token, ok := ctx.Value(JWTTokenContextKey).(string) if ok { @@ -42,9 +42,9 @@ } } -// ToGRPCContext moves JWT token from grpc metadata to context. Particularly +// GRPCToContext moves JWT token from grpc metadata to context. Particularly // userful for servers. -func ToGRPCContext() grpc.ServerRequestFunc { +func GRPCToContext() grpc.ServerRequestFunc { return func(ctx context.Context, md metadata.MD) context.Context { // capital "Key" is illegal in HTTP/2. authHeader, ok := md["authorization"] @@ -61,9 +61,9 @@ } } -// FromGRPCContext moves JWT token from context to grpc metadata. Particularly +// ContextToGRPC moves JWT token from context to grpc metadata. Particularly // useful for clients. -func FromGRPCContext() grpc.ClientRequestFunc { +func ContextToGRPC() 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 b04d76f..83d0f17 100644 --- a/auth/jwt/transport_test.go +++ b/auth/jwt/transport_test.go @@ -9,8 +9,8 @@ "google.golang.org/grpc/metadata" ) -func TestToHTTPContext(t *testing.T) { - reqFunc := ToHTTPContext() +func TestHTTPToContext(t *testing.T) { + reqFunc := HTTPToContext() // When the header doesn't exist ctx := reqFunc(context.Background(), &http.Request{}) @@ -38,8 +38,8 @@ } } -func TestFromHTTPContext(t *testing.T) { - reqFunc := FromHTTPContext() +func TestContextToHTTP(t *testing.T) { + reqFunc := ContextToHTTP() // No JWT Token is passed in the context ctx := context.Background() @@ -64,9 +64,9 @@ } } -func TestToGRPCContext(t *testing.T) { +func TestGRPCToContext(t *testing.T) { md := metadata.MD{} - reqFunc := ToGRPCContext() + reqFunc := GRPCToContext() // No Authorization header is passed ctx := reqFunc(context.Background(), md) @@ -96,8 +96,8 @@ } } -func TestFromGRPCContext(t *testing.T) { - reqFunc := FromGRPCContext() +func TestContextToGRPC(t *testing.T) { + reqFunc := ContextToGRPC() // No JWT Token is passed in the context ctx := context.Background()