From 9a22102fa8b1ce47571d5bba71e8f36895d21bf0 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Thu, 22 Jun 2023 20:46:36 +0100 Subject: [bugfix/chore] oauth entropy fix + media cleanup tasks rewrite (#1853) --- internal/gtscontext/context.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'internal/gtscontext/context.go') diff --git a/internal/gtscontext/context.go b/internal/gtscontext/context.go index c8cd42208..46f2899fa 100644 --- a/internal/gtscontext/context.go +++ b/internal/gtscontext/context.go @@ -41,8 +41,23 @@ const ( httpSigVerifierKey httpSigKey httpSigPubKeyIDKey + dryRunKey ) +// DryRun returns whether the "dryrun" context key has been set. This can be +// used to indicate to functions, (that support it), that only a dry-run of +// the operation should be performed. As opposed to making any permanent changes. +func DryRun(ctx context.Context) bool { + _, ok := ctx.Value(dryRunKey).(struct{}) + return ok +} + +// SetDryRun sets the "dryrun" context flag and returns this wrapped context. +// See DryRun() for further information on the "dryrun" context flag. +func SetDryRun(ctx context.Context) context.Context { + return context.WithValue(ctx, dryRunKey, struct{}{}) +} + // RequestID returns the request ID associated with context. This value will usually // be set by the request ID middleware handler, either pulling an existing supplied // value from request headers, or generating a unique new entry. This is useful for -- cgit v1.2.3