snapshot of https://github.com/ThreeDotsLabs/watermill.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
master / ci (push) Failing after 0s
Some checks failed
master / ci (push) Failing after 0s
This commit is contained in:
27
components/cqrs/ctx.go
Normal file
27
components/cqrs/ctx.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package cqrs
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ThreeDotsLabs/watermill/message"
|
||||
)
|
||||
|
||||
type ctxKey string
|
||||
|
||||
const (
|
||||
originalMessage ctxKey = "original_message"
|
||||
)
|
||||
|
||||
// OriginalMessageFromCtx returns the original message that was received by the event/command handler.
|
||||
func OriginalMessageFromCtx(ctx context.Context) *message.Message {
|
||||
val, ok := ctx.Value(originalMessage).(*message.Message)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
// CtxWithOriginalMessage returns a new context with the original message attached.
|
||||
func CtxWithOriginalMessage(ctx context.Context, msg *message.Message) context.Context {
|
||||
return context.WithValue(ctx, originalMessage, msg)
|
||||
}
|
||||
Reference in New Issue
Block a user