1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
From: Shengjing Zhu <i@zhsj.me>
Date: Thu, 14 Sep 2017 16:21:46 +0800
Subject: Add NewContext and FromContext back to metadata package
These are remove in https://github.com/grpc/grpc-go/pull/1392
We try to not break the API since some packages in the Debian
archive are not updated.
Forwarded: not-needed
Signed-off-by: Shengjing Zhu <i@zhsj.me>
---
metadata/metadata.go | 10 ++++++++++
1 file changed, 10 insertions(+)
--- a/metadata/metadata.go
+++ b/metadata/metadata.go
@@ -137,6 +137,11 @@
type mdIncomingKey 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.
func NewIncomingContext(ctx context.Context, md MD) context.Context {
return context.WithValue(ctx, mdIncomingKey{}, md)
@@ -164,6 +169,11 @@
return context.WithValue(ctx, mdOutgoingKey{}, rawMD{md: md.md, added: added})
}
+// 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
// returned MD should not be modified. Writing to it may cause races.
// Modification should be made to copies of the returned MD.
|