2020-07-13 05:25:48 +00:00
|
|
|
package bbgo
|
|
|
|
|
2020-07-16 07:36:02 +00:00
|
|
|
type Notifier interface {
|
2020-10-22 02:47:54 +00:00
|
|
|
NotifyTo(channel, format string, args ...interface{}) error
|
|
|
|
Notify(format string, args ...interface{}) error
|
2020-07-16 07:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type NullNotifier struct{}
|
|
|
|
|
2020-10-22 02:47:54 +00:00
|
|
|
func (n *NullNotifier) NotifyTo(channel, format string, args ...interface{}) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-21 11:52:55 +00:00
|
|
|
func (n *NullNotifier) Notify(format string, args ...interface{}) error {
|
|
|
|
return nil
|
2020-07-16 07:36:02 +00:00
|
|
|
}
|
2020-10-22 02:54:03 +00:00
|
|
|
|
|
|
|
type Notifiability struct {
|
|
|
|
notifiers []Notifier
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Notifiability) AddNotifier(notifier Notifier) {
|
|
|
|
m.notifiers = append(m.notifiers, notifier)
|
|
|
|
}
|
|
|
|
|
2020-10-26 05:40:43 +00:00
|
|
|
func (m *Notifiability) Notify(msg string, args ...interface{}) (err error) {
|
2020-10-22 02:54:03 +00:00
|
|
|
for _, n := range m.notifiers {
|
2020-10-26 05:40:43 +00:00
|
|
|
if err2 := n.Notify(msg, args...); err2 != nil {
|
|
|
|
err = err2
|
|
|
|
}
|
2020-10-22 06:45:05 +00:00
|
|
|
}
|
2020-10-26 05:40:43 +00:00
|
|
|
|
|
|
|
return err
|
2020-10-22 06:45:05 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 05:40:43 +00:00
|
|
|
func (m *Notifiability) NotifyTo(channel, msg string, args ...interface{}) (err error) {
|
2020-10-22 06:45:05 +00:00
|
|
|
for _, n := range m.notifiers {
|
2020-10-26 05:40:43 +00:00
|
|
|
if err2 := n.NotifyTo(channel, msg, args...); err2 != nil {
|
|
|
|
err = err2
|
|
|
|
}
|
2020-10-22 02:54:03 +00:00
|
|
|
}
|
2020-10-26 05:40:43 +00:00
|
|
|
|
|
|
|
return err
|
2020-10-22 02:54:03 +00:00
|
|
|
}
|