// LogError logs the error to the owner of the context. // // If this context was created with ContextWithErrorLog, then this method // passes the error to context creator over an unbuffered channel. // // If this context was created by other means, this method is a no-op. func LogError(ctx context.Context, err error) { v := ctx.Value(errLogKey) errs, ok := v.(privateChanType) if !ok { return } errs <- err }
func MetadataFromContext(ctx context.Context) (Metadata, error) { value := ctx.Value(metadataKey) if value != nil { metadata, ok := value.(Metadata) if ok { return metadata, nil } } return nil, errors.New("context contains no metadata") }