zrepl/endpoint/context.go

28 lines
463 B
Go
Raw Permalink Normal View History

package endpoint
import (
"context"
2019-03-22 19:41:12 +01:00
"github.com/zrepl/zrepl/logger"
)
type contextKey int
const (
contextKeyLogger contextKey = iota
ClientIdentityKey
)
type Logger = logger.Logger
func WithLogger(ctx context.Context, log Logger) context.Context {
return context.WithValue(ctx, contextKeyLogger, log)
}
func getLogger(ctx context.Context) Logger {
if l, ok := ctx.Value(contextKeyLogger).(Logger); ok {
return l
}
return logger.NewNullLogger()
}