Get returns the string value associated with the passed key from the carrier's incoming context metadata. It returns an empty string if the key is not present in the carrier's context or if the value associated with the key is empty. If multiple values are present for a key, it returns the last on
(key string)
| 50 | // |
| 51 | // If multiple values are present for a key, it returns the last one. |
| 52 | func (c *IncomingCarrier) Get(key string) string { |
| 53 | values := metadata.ValueFromIncomingContext(c.ctx, key) |
| 54 | if len(values) == 0 { |
| 55 | return "" |
| 56 | } |
| 57 | return values[len(values)-1] |
| 58 | } |
| 59 | |
| 60 | // Set just logs an error. It implements the `TextMapCarrier` interface but |
| 61 | // should not be used with `IncomingCarrier`. |