mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 17:44:29 +00:00
39 lines
663 B
Go
39 lines
663 B
Go
|
package sync
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/ledgerwatch/log/v3"
|
||
|
)
|
||
|
|
||
|
type ctxKey int
|
||
|
|
||
|
const (
|
||
|
ckLogger ctxKey = iota
|
||
|
ckTempDir
|
||
|
)
|
||
|
|
||
|
func WithLogger(ctx context.Context, logger log.Logger) context.Context {
|
||
|
return context.WithValue(ctx, ckLogger, logger)
|
||
|
}
|
||
|
|
||
|
func Logger(ctx context.Context) log.Logger {
|
||
|
if logger, ok := ctx.Value(ckLogger).(log.Logger); ok {
|
||
|
return logger
|
||
|
}
|
||
|
|
||
|
return log.Root()
|
||
|
}
|
||
|
|
||
|
func WithTempDir(ctx context.Context, tempDir string) context.Context {
|
||
|
return context.WithValue(ctx, ckTempDir, tempDir)
|
||
|
}
|
||
|
|
||
|
func TempDir(ctx context.Context) string {
|
||
|
if tempDir, ok := ctx.Value(ckTempDir).(string); ok {
|
||
|
return tempDir
|
||
|
}
|
||
|
|
||
|
return ""
|
||
|
}
|