diff options
Diffstat (limited to 'pkg/common/dryrun.go')
-rw-r--r-- | pkg/common/dryrun.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/common/dryrun.go b/pkg/common/dryrun.go new file mode 100644 index 0000000..2d5a14e --- /dev/null +++ b/pkg/common/dryrun.go @@ -0,0 +1,25 @@ +package common + +import ( + "context" +) + +type dryrunContextKey string + +const dryrunContextKeyVal = dryrunContextKey("dryrun") + +// Dryrun returns true if the current context is dryrun +func Dryrun(ctx context.Context) bool { + val := ctx.Value(dryrunContextKeyVal) + if val != nil { + if dryrun, ok := val.(bool); ok { + return dryrun + } + } + return false +} + +// WithDryrun adds a value to the context for dryrun +func WithDryrun(ctx context.Context, dryrun bool) context.Context { + return context.WithValue(ctx, dryrunContextKeyVal, dryrun) +} |