metadata: Remove NewContext and FromContext for gRFC L7 (#1392)
This commit is contained in:
@ -104,11 +104,6 @@ func Join(mds ...MD) MD {
|
|||||||
type mdIncomingKey struct{}
|
type mdIncomingKey struct{}
|
||||||
type mdOutgoingKey struct{}
|
type mdOutgoingKey struct{}
|
||||||
|
|
||||||
// NewContext is a wrapper for NewOutgoingContext(ctx, md). Deprecated.
|
|
||||||
func NewContext(ctx context.Context, md MD) context.Context {
|
|
||||||
return NewOutgoingContext(ctx, md)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewIncomingContext creates a new context with incoming md attached.
|
// NewIncomingContext creates a new context with incoming md attached.
|
||||||
func NewIncomingContext(ctx context.Context, md MD) context.Context {
|
func NewIncomingContext(ctx context.Context, md MD) context.Context {
|
||||||
return context.WithValue(ctx, mdIncomingKey{}, md)
|
return context.WithValue(ctx, mdIncomingKey{}, md)
|
||||||
@ -119,11 +114,6 @@ func NewOutgoingContext(ctx context.Context, md MD) context.Context {
|
|||||||
return context.WithValue(ctx, mdOutgoingKey{}, md)
|
return context.WithValue(ctx, mdOutgoingKey{}, md)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromContext is a wrapper for FromIncomingContext(ctx). Deprecated.
|
|
||||||
func FromContext(ctx context.Context) (md MD, ok bool) {
|
|
||||||
return FromIncomingContext(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FromIncomingContext returns the incoming metadata in ctx if it exists. The
|
// FromIncomingContext returns the incoming metadata in ctx if it exists. The
|
||||||
// returned MD should not be modified. Writing to it may cause races.
|
// returned MD should not be modified. Writing to it may cause races.
|
||||||
// Modification should be made to copies of the returned MD.
|
// Modification should be made to copies of the returned MD.
|
||||||
|
@ -106,7 +106,7 @@ func (s *testServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *testServer) ClientStreamCall(stream testpb.TestService_ClientStreamCallServer) error {
|
func (s *testServer) ClientStreamCall(stream testpb.TestService_ClientStreamCallServer) error {
|
||||||
md, ok := metadata.FromContext(stream.Context())
|
md, ok := metadata.FromIncomingContext(stream.Context())
|
||||||
if ok {
|
if ok {
|
||||||
if err := stream.SendHeader(md); err != nil {
|
if err := stream.SendHeader(md); err != nil {
|
||||||
return grpc.Errorf(grpc.Code(err), "%v.SendHeader(%v) = %v, want %v", stream, md, err, nil)
|
return grpc.Errorf(grpc.Code(err), "%v.SendHeader(%v) = %v, want %v", stream, md, err, nil)
|
||||||
@ -130,7 +130,7 @@ func (s *testServer) ClientStreamCall(stream testpb.TestService_ClientStreamCall
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *testServer) ServerStreamCall(in *testpb.SimpleRequest, stream testpb.TestService_ServerStreamCallServer) error {
|
func (s *testServer) ServerStreamCall(in *testpb.SimpleRequest, stream testpb.TestService_ServerStreamCallServer) error {
|
||||||
md, ok := metadata.FromContext(stream.Context())
|
md, ok := metadata.FromIncomingContext(stream.Context())
|
||||||
if ok {
|
if ok {
|
||||||
if err := stream.SendHeader(md); err != nil {
|
if err := stream.SendHeader(md); err != nil {
|
||||||
return grpc.Errorf(grpc.Code(err), "%v.SendHeader(%v) = %v, want %v", stream, md, err, nil)
|
return grpc.Errorf(grpc.Code(err), "%v.SendHeader(%v) = %v, want %v", stream, md, err, nil)
|
||||||
@ -330,7 +330,7 @@ func (te *test) doClientStreamCall(c *rpcConfig) ([]*testpb.SimpleRequest, *test
|
|||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
tc := testpb.NewTestServiceClient(te.clientConn())
|
tc := testpb.NewTestServiceClient(te.clientConn())
|
||||||
stream, err := tc.ClientStreamCall(metadata.NewContext(context.Background(), testMetadata), grpc.FailFast(c.failfast))
|
stream, err := tc.ClientStreamCall(metadata.NewOutgoingContext(context.Background(), testMetadata), grpc.FailFast(c.failfast))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return reqs, resp, err
|
return reqs, resp, err
|
||||||
}
|
}
|
||||||
@ -365,7 +365,7 @@ func (te *test) doServerStreamCall(c *rpcConfig) (*testpb.SimpleRequest, []*test
|
|||||||
startID = errorID
|
startID = errorID
|
||||||
}
|
}
|
||||||
req = &testpb.SimpleRequest{Id: startID}
|
req = &testpb.SimpleRequest{Id: startID}
|
||||||
stream, err := tc.ServerStreamCall(metadata.NewContext(context.Background(), testMetadata), req, grpc.FailFast(c.failfast))
|
stream, err := tc.ServerStreamCall(metadata.NewOutgoingContext(context.Background(), testMetadata), req, grpc.FailFast(c.failfast))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return req, resps, err
|
return req, resps, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user