mirror of https://github.com/databricks/cli.git
35 lines
680 B
Go
35 lines
680 B
Go
package testdiff
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type key int
|
|
|
|
const (
|
|
replacementsMapKey = key(1)
|
|
)
|
|
|
|
func WithReplacementsMap(ctx context.Context) (context.Context, *ReplacementsContext) {
|
|
value := ctx.Value(replacementsMapKey)
|
|
if value != nil {
|
|
if existingMap, ok := value.(*ReplacementsContext); ok {
|
|
return ctx, existingMap
|
|
}
|
|
}
|
|
|
|
newMap := &ReplacementsContext{}
|
|
ctx = context.WithValue(ctx, replacementsMapKey, newMap)
|
|
return ctx, newMap
|
|
}
|
|
|
|
func GetReplacementsMap(ctx context.Context) *ReplacementsContext {
|
|
value := ctx.Value(replacementsMapKey)
|
|
if value != nil {
|
|
if existingMap, ok := value.(*ReplacementsContext); ok {
|
|
return existingMap
|
|
}
|
|
}
|
|
return nil
|
|
}
|