-
Notifications
You must be signed in to change notification settings - Fork 1
/
notifications.go
55 lines (44 loc) · 988 Bytes
/
notifications.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
46
47
48
49
50
51
52
53
54
55
package webutils
import "context"
// Notifier is responsible for publishing notifications
type Notifier interface {
Notify(
ctx context.Context,
opts NotificationOpts,
) error
}
// NotificationPriority represents a priority
type NotificationPriority int
// NotificationPriorities
const (
NotificationPriorityLow NotificationPriority = iota + 1
NotificationPriorityMedium
NotificationPriorityHigh
)
func (p NotificationPriority) String() string {
if p == NotificationPriorityLow {
return "Low"
}
if p == NotificationPriorityMedium {
return "Medium"
}
if p == NotificationPriorityHigh {
return "High"
}
return ""
}
// NotificationOpts represents a notification
type NotificationOpts struct {
Message string
Subject string
Priority NotificationPriority
Error error
Metadata map[string]string
}
// Validate NotificationOpts
func (opts *NotificationOpts) Validate() error {
if opts.Message == "" {
return ErrNoNotificationMessage
}
return nil
}