1
0
mirror of https://github.com/eventials/goevents.git synced 2025-04-29 13:49:26 +08:00

40 lines
780 B
Go
Raw Normal View History

2017-10-05 17:38:18 -03:00
package messaging
import (
"context"
2018-04-24 15:41:26 -03:00
"time"
2017-10-05 17:38:18 -03:00
)
type Event struct {
2018-04-24 15:41:26 -03:00
Id string
Action string
Timestamp time.Time
Body []byte
Ack func(multiple bool) error
Nack func(multiple, requeue bool) error
Reject func(requeue bool) error
2018-04-24 15:41:26 -03:00
ctx context.Context
2017-10-05 17:38:18 -03:00
}
// WithContext returns a shallow copy of Event with its context changed to ctx.
// The provided ctx must be non-nil.
2018-10-29 14:22:17 -03:00
func (e Event) WithContext(ctx context.Context) Event {
2017-10-05 17:38:18 -03:00
if ctx == nil {
panic("nil context")
}
2018-10-29 14:22:17 -03:00
e.ctx = ctx
2017-10-05 17:38:18 -03:00
2018-10-29 14:22:17 -03:00
return e
2017-10-05 17:38:18 -03:00
}
2018-10-29 14:22:17 -03:00
// Context returns the current context; if nil, it defaults to the background context.
2017-10-05 17:38:18 -03:00
// To change the context, use WithContext.
2018-10-29 14:22:17 -03:00
func (e Event) Context() context.Context {
2017-10-05 17:38:18 -03:00
if e.ctx != nil {
return e.ctx
}
return context.Background()
}