endpoints: fix sample when both api-key and token are specified
Existing code is broken where it would attempt to create a context
inside a context as opposed to appending both keys to the context.
Therefore, when both api-key and token are specified, only token
would take effect and not api-key.
@@ -91,11 +91,11 @@ func main() {
ctx := context.Background()
if *key != "" {
log.Printf("Using API key: %s", *key)
- ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs("x-api-key", *key))
+ ctx = metadata.AppendToOutgoingContext(ctx, "x-api-key", *key)
}
if *token != "" {
log.Printf("Using authentication token: %s", *token)
- ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs("Authorization", fmt.Sprintf("Bearer %s", *token)))
+ ctx = metadata.AppendToOutgoingContext(ctx, "Authorization", fmt.Sprintf("Bearer %s", *token))
}
// Contact the server and print out its response.
