mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 14:16:21 +00:00
eeca435064
Update vendor Integrate rendezvous into status node Add a test with failover using rendezvous Use multiple servers in client Use discovery V5 by default and test that node can be started with rendezvous discovet Fix linter Update rendezvous client to one with instrumented stream Address feedback Fix test with updated topic limits Apply several suggestions Change log to debug for request errors because we continue execution Remove web3js after rebase Update rendezvous package
39 lines
986 B
Go
39 lines
986 B
Go
package log
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
)
|
|
|
|
type key int
|
|
|
|
const metadataKey key = 0
|
|
|
|
// ContextWithLoggable returns a derived context which contains the provided
|
|
// Loggable. Any Events logged with the derived context will include the
|
|
// provided Loggable.
|
|
func ContextWithLoggable(ctx context.Context, l Loggable) context.Context {
|
|
existing, err := MetadataFromContext(ctx)
|
|
if err != nil {
|
|
// context does not contain meta. just set the new metadata
|
|
child := context.WithValue(ctx, metadataKey, Metadata(l.Loggable()))
|
|
return child
|
|
}
|
|
|
|
merged := DeepMerge(existing, l.Loggable())
|
|
child := context.WithValue(ctx, metadataKey, merged)
|
|
return child
|
|
}
|
|
|
|
// MetadataFromContext extracts Matadata from a given context's value.
|
|
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")
|
|
}
|