-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification_handler_definition.go
34 lines (27 loc) · 1.1 KB
/
notification_handler_definition.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
package mediator
import "reflect"
// NotificationHandlerDefinition is a definition of a notification handler
// It is used to define a notification handler and its associated notification type
type NotificationHandlerDefinition interface {
NotificationType() reflect.Type
Handler() interface{}
}
// NewNotificationHandlerDefinition creates a new notification handler definition
func NewNotificationHandlerDefinition[TNotification Notification](handler NotificationHandler[TNotification]) NotificationHandlerDefinition {
var notification TNotification
notificationType := reflect.TypeOf(notification)
return TypedNotificationHandlerDefinition[TNotification]{
notificationType: notificationType,
handler: handler,
}
}
type TypedNotificationHandlerDefinition[TNotification Notification] struct {
notificationType reflect.Type
handler NotificationHandler[TNotification]
}
func (t TypedNotificationHandlerDefinition[TNotification]) NotificationType() reflect.Type {
return t.notificationType
}
func (t TypedNotificationHandlerDefinition[TNotification]) Handler() interface{} {
return t.handler
}