forked from apolloconfig/agollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_event.go
69 lines (58 loc) · 1.24 KB
/
change_event.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
package agollo
const (
ADDED ConfigChangeType = iota
MODIFIED
DELETED
)
var (
notifyChan chan *ChangeEvent
)
//config change type
type ConfigChangeType int
//config change event
type ChangeEvent struct {
Namespace string
Changes map[string]*ConfigChange
}
type ConfigChange struct {
OldValue string
NewValue string
ChangeType ConfigChangeType
}
//list config change event
func ListenChangeEvent() <-chan *ChangeEvent {
if notifyChan == nil {
notifyChan = make(chan *ChangeEvent, 1)
}
return notifyChan
}
//push config change event
func pushChangeEvent(event *ChangeEvent) {
// if channel is null ,mean no listener,don't need to push msg
if notifyChan == nil {
return
}
notifyChan <- event
}
//create modify config change
func createModifyConfigChange(oldValue string, newValue string) *ConfigChange {
return &ConfigChange{
OldValue: oldValue,
NewValue: newValue,
ChangeType: MODIFIED,
}
}
//create add config change
func createAddConfigChange(newValue string) *ConfigChange {
return &ConfigChange{
NewValue: newValue,
ChangeType: ADDED,
}
}
//create delete config change
func createDeletedConfigChange(oldValue string) *ConfigChange {
return &ConfigChange{
OldValue: oldValue,
ChangeType: DELETED,
}
}