| 1234567891011121314151617181920212223242526 |
- package context
- import (
- "context"
- "fmt"
- "google.golang.org/grpc/metadata"
- )
- func AppendToContext(ctx context.Context, key string, value interface{}) context.Context {
- ctx = context.WithValue(ctx, key, value)
- _value := ""
- switch value.(type) {
- case []byte:
- _value = string(value.([]byte))
- break
- case string:
- _value = value.(string)
- break
- default:
- _value = fmt.Sprint(value)
- break
- }
- ctx = metadata.AppendToOutgoingContext(ctx, key, _value)
- return ctx
- }
|