1
0
mirror of https://github.com/nikoksr/notify.git synced 2024-11-24 08:22:18 +02:00
notify/send.go
2021-01-25 05:05:28 +01:00

32 lines
561 B
Go

package notify
import (
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)
// Send calls the underlying notification services to send the given message to their respective endpoints.
func (n Notify) Send(subject, message string) error {
if n.Disabled {
return nil
}
var eg errgroup.Group
for _, service := range n.notifiers {
if service != nil {
s := service
eg.Go(func() error {
return s.Send(subject, message)
})
}
}
err := eg.Wait()
if err != nil {
err = errors.Wrap(ErrSendNotification, err.Error())
}
return err
}