git.zd.zone/hrpc/hrpc@v0.0.12/codec/codec.go (about) 1 package codec 2 3 import ( 4 "context" 5 6 "google.golang.org/grpc/metadata" 7 ) 8 9 // CopyCcontext will copy the input context of `in` to create a new one 10 func CopyCcontext(in context.Context) context.Context { 11 c := context.Background() 12 newMsg := Message(c) 13 oldMsg := Message(in) 14 15 newMsg.WithServerName(oldMsg.ServerName()) 16 newMsg.WithNamespace(oldMsg.Namespace()) 17 newMsg.WithRequestTimeout(oldMsg.RequestTimeout()) 18 newMsg.WithTraceID(oldMsg.TraceID()) 19 20 c = metadata.NewOutgoingContext( 21 c, oldMsg.Metadata(), 22 ) 23 c = metadata.NewIncomingContext( 24 c, oldMsg.Metadata(), 25 ) 26 return c 27 }