2023-04-06 10:54:58 +00:00
|
|
|
package cmdio
|
2023-03-29 12:58:09 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|