bbgo_origin/pkg/bbgo/notifier.go

45 lines
948 B
Go
Raw Normal View History

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)
}
func (m *Notifiability) Notify(msg string, args ...interface{}) (err error) {
2020-10-22 02:54:03 +00:00
for _, n := range m.notifiers {
if err2 := n.Notify(msg, args...); err2 != nil {
err = err2
}
2020-10-22 06:45:05 +00:00
}
return err
2020-10-22 06:45:05 +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 {
if err2 := n.NotifyTo(channel, msg, args...); err2 != nil {
err = err2
}
2020-10-22 02:54:03 +00:00
}
return err
2020-10-22 02:54:03 +00:00
}