MCPcopy
hub / github.com/grpc/grpc-go / AppendToOutgoingContext

Function AppendToOutgoingContext

metadata/metadata.go:179–192  ·  view source on GitHub ↗

AppendToOutgoingContext returns a new context with the provided kv merged with any existing metadata in the context. Please refer to the documentation of Pairs for a description of kv.

(ctx context.Context, kv ...string)

Source from the content-addressed store, hash-verified

177// with any existing metadata in the context. Please refer to the documentation
178// of Pairs for a description of kv.
179func AppendToOutgoingContext(ctx context.Context, kv ...string) context.Context {
180 if len(kv)%2 == 1 {
181 panic(fmt.Sprintf("metadata: AppendToOutgoingContext got an odd number of input pairs for metadata: %d", len(kv)))
182 }
183 md, _ := ctx.Value(mdOutgoingKey{}).(rawMD)
184 added := make([][]string, len(md.added)+1)
185 copy(added, md.added)
186 kvCopy := make([]string, 0, len(kv))
187 for i := 0; i < len(kv); i += 2 {
188 kvCopy = append(kvCopy, strings.ToLower(kv[i]), kv[i+1])
189 }
190 added[len(added)-1] = kvCopy
191 return context.WithValue(ctx, mdOutgoingKey{}, rawMD{md: md.md, added: added})
192}
193
194// FromIncomingContext returns the incoming metadata in ctx if it exists.
195//

Calls 2

WithValueMethod · 0.80
ValueMethod · 0.45