-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin/archive): allow custom mail id
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package archive | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
const ( | ||
ctxMailID = ctxKey("mail_id") | ||
) | ||
|
||
type ctxKey string | ||
|
||
// WithMailID returns a new Context that carries the given UUID. Mails that are | ||
// archived with that Context will use that UUID as their UUID when stored in a | ||
// database. | ||
func WithMailID(ctx context.Context, id uuid.UUID) context.Context { | ||
return context.WithValue(ctx, ctxMailID, id) | ||
} | ||
|
||
// MailIDFromContext returns the mail UUID from the given Context, or uuid.Nil | ||
// if the Context has no mail UUID. | ||
func MailIDFromContext(ctx context.Context) uuid.UUID { | ||
val := ctx.Value(ctxMailID) | ||
if val == nil { | ||
return uuid.Nil | ||
} | ||
|
||
id, ok := val.(uuid.UUID) | ||
if !ok { | ||
return uuid.Nil | ||
} | ||
|
||
return id | ||
} |