-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbridge.go
79 lines (62 loc) · 1.79 KB
/
bridge.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
71
72
73
74
75
76
77
78
79
package bridge
import "fmt"
//IMessage 发送消息接口
type IMessage interface {
NoticeUser(text string)
Priority() int
}
//ISMSMessage send SMS MSG
type ISMSMessage interface {
//延迟接口的实现到其他类中
NoticeUser(text string, noticeMessage IMessage)
}
//WSMessage MSG
type WSMessage struct {
Handler ISMSMessage //持有进一步实现的引用关系
Level int
}
//NoticeUser by SMS
func (w *WSMessage) NoticeUser(text string) {
//转递消息给其他对象,相当于承上启下
fmt.Println("Websocket Notice User...", text)
//转递消息给其他对象,相当于承上启下,并且需要把上下文变量传递下去
if w.Handler != nil {
w.Handler.NoticeUser(text, w)
}
}
//Priority of SMS
func (w *WSMessage) Priority() int {
return w.Level
}
//EmailMessage MSG
type EmailMessage struct {
Handler ISMSMessage
Level int
}
//NoticeUser by SMS
func (e *EmailMessage) NoticeUser(text string) {
//转递消息给其他对象,相当于承上启下,并且需要把上下文变量传递下去
fmt.Println("Email Notice User...", text)
if e.Handler != nil {
e.Handler.NoticeUser(text, e)
}
}
//Priority of SMS
func (e *EmailMessage) Priority() int {
return e.Level
}
///需要实现具体的消息发送行为
//EmergencyWSMessage 紧急的短信消息
type EmergencyWSMessage struct {
}
//NoticeUser by email
func (e *EmergencyWSMessage) NoticeUser(text string, noticeMessage IMessage) {
fmt.Println("Notice User", text, " By Websocket:", "with Level: ", noticeMessage.Priority())
}
//EmergencyEmailMessage 紧急的短信消息
type EmergencyEmailMessage struct {
}
//NoticeUser by email
func (e *EmergencyEmailMessage) NoticeUser(text string, noticeMessage IMessage) {
fmt.Println("Notice User:", text, " By Email:", "with Level: ", noticeMessage.Priority())
}