mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
45 lines
948 B
Go
45 lines
948 B
Go
package bbgo
|
|
|
|
type Notifier interface {
|
|
NotifyTo(channel, format string, args ...interface{}) error
|
|
Notify(format string, args ...interface{}) error
|
|
}
|
|
|
|
type NullNotifier struct{}
|
|
|
|
func (n *NullNotifier) NotifyTo(channel, format string, args ...interface{}) error {
|
|
return nil
|
|
}
|
|
|
|
func (n *NullNotifier) Notify(format string, args ...interface{}) error {
|
|
return nil
|
|
}
|
|
|
|
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) {
|
|
for _, n := range m.notifiers {
|
|
if err2 := n.Notify(msg, args...); err2 != nil {
|
|
err = err2
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (m *Notifiability) NotifyTo(channel, msg string, args ...interface{}) (err error) {
|
|
for _, n := range m.notifiers {
|
|
if err2 := n.NotifyTo(channel, msg, args...); err2 != nil {
|
|
err = err2
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|