Use stdlib context instead of golang.org/x/net/context#421
Use stdlib context instead of golang.org/x/net/context#421peterbourgon merged 6 commits intomasterfrom
Conversation
|
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" | |||
|
|
|||
|
Since grpc uses 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 // ...
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 // 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 {
// ...
} |
2ccb050 to
1567601
Compare
1567601 to
1f1ad4d
Compare
Use stdlib context instead of golang.org/x/net/context
Addresses #420 (heyoh)