databricks-cli/libs/progress/context.go

21 lines
509 B
Go
Raw Normal View History

2023-03-29 12:58:09 +00:00
package progress
import (
"context"
)
type progressLogger int
var progressLoggerKey progressLogger
// NewContext returns a new Context that carries the specified progress logger.
func NewContext(ctx context.Context, logger *Logger) context.Context {
return context.WithValue(ctx, progressLoggerKey, logger)
}
// FromContext returns the progress logger value stored in ctx, if any.
func FromContext(ctx context.Context) (*Logger, bool) {
u, ok := ctx.Value(progressLoggerKey).(*Logger)
return u, ok
}