/
message.go
70 lines (62 loc) · 1.66 KB
/
message.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package notification
import (
"database/sql/driver"
"fmt"
)
//go:generate go run golang.org/x/tools/cmd/stringer -type MessageType
// A Message contains information that can be provided
// to a user for notification.
type Message interface {
ID() string
Type() MessageType
Destination() Dest
}
// MessageType indicates the type of notification message.
type MessageType int
// Allowed types
const (
MessageTypeUnknown MessageType = iota
MessageTypeAlert
MessageTypeAlertStatus
MessageTypeTest
MessageTypeVerification
MessageTypeAlertBundle
MessageTypeAlertStatusBundle
)
func (s MessageType) Value() (driver.Value, error) {
switch s {
case MessageTypeAlert:
return "alert_notification", nil
case MessageTypeAlertStatus:
return "alert_status_update", nil
case MessageTypeTest:
return "test_notification", nil
case MessageTypeVerification:
return "verification_message", nil
case MessageTypeAlertBundle:
return "alert_notification_bundle", nil
case MessageTypeAlertStatusBundle:
return "alert_status_update_bundle", nil
}
return nil, fmt.Errorf("could not process unknown type for MessageType %s", s)
}
func (s *MessageType) Scan(value interface{}) error {
str := value.(string)
switch str {
case "alert_notification":
*s = MessageTypeAlert
case "alert_status_update":
*s = MessageTypeAlertStatus
case "test_notification":
*s = MessageTypeTest
case "verification_message":
*s = MessageTypeVerification
case "alert_notification_bundle":
*s = MessageTypeAlertBundle
case "alert_status_update_bundle":
*s = MessageTypeAlertStatusBundle
default:
return fmt.Errorf("could not process unknown type for MessageType %str", str)
}
return nil
}