-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.go
45 lines (37 loc) · 1.48 KB
/
publish.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package mediator
import (
"context"
)
type PublishOptions struct {
NotificationDefinitionHandlers []NotificationHandlerDefinition
PublishStrategy PublishStrategy
}
// WithNotificationDefinitionHandler adds a notification handler to the container
func WithNotificationDefinitionHandler(notificationHandler NotificationHandlerDefinition) func(*PublishOptions) {
return func(options *PublishOptions) {
options.NotificationDefinitionHandlers = append(options.NotificationDefinitionHandlers, notificationHandler)
}
}
// WithNotificationDefinitionHandlers adds notification handlers to the container
func WithNotificationDefinitionHandlers(notificationHandlers ...NotificationHandlerDefinition) func(*PublishOptions) {
return func(options *PublishOptions) {
options.NotificationDefinitionHandlers = append(options.NotificationDefinitionHandlers, notificationHandlers...)
}
}
// WithPublishStrategy sets the strategy to publish notifications
func WithPublishStrategy(strategy PublishStrategy) func(*PublishOptions) {
return func(options *PublishOptions) {
options.PublishStrategy = strategy
}
}
// Publisher is the interface to publish notifications
type Publisher interface {
Publish(ctx context.Context, notification interface{}) error
}
type LaunchHandler func(context.Context, interface{}) error
// PublishStrategy is the strategy to publish notifications
type PublishStrategy interface {
Execute(ctx context.Context,
handlers []interface{},
launcher LaunchHandler) error
}