Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stdlib context instead of golang.org/x/net/context #421

Merged
merged 6 commits into from
Feb 4, 2017

Conversation

peterbourgon
Copy link
Member

Addresses #420 (heyoh)

@peterbourgon
Copy link
Member Author

peterbourgon commented Dec 25, 2016

Hmm, gRPC still uses x/net/context, which means it can't produce or use endpoints that use plain context. Unless someone has a coercion trick I think we're stuck until gRPC makes the switch.

Relevant issue grpc/grpc-go#711

@@ -9,7 +9,7 @@ import (
"fmt"
"time"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove empty line-break

@Ayiga
Copy link
Contributor

Ayiga commented Jan 14, 2017

Since grpc uses golang.org/x/net/context.Context, and it's an interface, the only real issue that we're having is grpc Server method signature's aren't directly equivalent, right?

Would it be a decent solution, for the time being, to have a partial mix?

For example, I can get the addsvc working by changing one file in 3 places transport_grpc.go:

// ...
import (
	"context"

	gcontext "golang.org/x/net/context"
// ...
)
// ...
func (s *grpcServer) Sum(ctx gcontext.Context, req *pb.SumRequest) (*pb.SumReply, error) {
// ...
}
// ...
func (s *grpcServer) Concat(ctx gcontext.Context, req *pb.ConcatRequest) (*pb.ConcatReply, error) {
// ...
}
// ...

Is this a simple enough solution? I understand the need to try and make this as seamless and easy to use as possible for people. But the only other possible solution, I can see as being reasonable, is to create a Middleware / Shim / Adapter for submitting to grpc itself.

func MakeGRPCShimServer(server *grpcServer) pb.AddServer {
    return grpcShimServer {
        grpcServer: server,
   }
}

type grpcShimServer struct {
    grpcServer *grpcServer
}

// A shim Sum method for function matching.
func (s *grpcShimServer) Sum(ctx gcontext.Context, req *pb.SumRequest) (*pb.SumReply, error) {
   return  s.grpcServer.Sum(ctx, req)
}

func (s *grpcShimServer) Concat(ctx gcontext.Context, req *pb.ConcatRequest) (*pb.ConcatReply, error) {
    return s.grpcServer.Concat(ctx, req)
}

Then, of course, you'd have to the return type of the MakeGRPCServer function, and probably introduce a new interface so it can be used still:

// Server API for Add service
type AddServer interface {
	// Sums two integers.
	Sum(context.Context, *SumRequest) (*SumReply, error)
	// Concatenates two strings
	Concat(context.Context, *ConcatRequest) (*ConcatReply, error)
}

// MakeGRPCServer makes a set of endpoints available as a gRPC AddServer.
func MakeGRPCServer(ctx context.Context, endpoints Endpoints, tracer stdopentracing.Tracer, logger log.Logger) AddServer {
// ...
}

@peterbourgon peterbourgon mentioned this pull request Jan 16, 2017
6 tasks
@peterbourgon peterbourgon merged commit c5e750d into master Feb 4, 2017
@peterbourgon peterbourgon deleted the stdlib-context branch February 4, 2017 01:54
jamesgist pushed a commit to jamesgist/kit that referenced this pull request Nov 1, 2024
Use stdlib context instead of golang.org/x/net/context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants