-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathnotifiable.go
More file actions
33 lines (28 loc) · 813 Bytes
/
notifiable.go
File metadata and controls
33 lines (28 loc) · 813 Bytes
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
package sensor
import "github.com/stackrox/rox/sensor/common"
// offlineAware is meant to replace common.Notifiable for non-components, so that a pkg unrelated to Sensor
// is not forced to import sensor code.
type offlineAware interface {
GoOnline()
GoOffline()
}
// wrapNotifiable makes offlineAware struct implement the Notifiable interface
func wrapNotifiable(oa offlineAware, name string) common.Notifiable {
return ¬ifiableImpl{
name: name,
oa: oa,
}
}
type notifiableImpl struct {
name string
oa offlineAware
}
func (ni *notifiableImpl) Notify(e common.SensorComponentEvent) {
log.Info(common.LogSensorComponentEvent(e, ni.name))
switch e {
case common.SensorComponentEventCentralReachable:
ni.oa.GoOnline()
case common.SensorComponentEventOfflineMode:
ni.oa.GoOffline()
}
}