webhookd/pkg/notification/notifier.go

29 lines
633 B
Go
Raw Normal View History

package notification
import (
"github.com/ncarlier/webhookd/pkg/logger"
)
// Notifier is able to send a notification.
type Notifier interface {
2022-05-26 07:05:49 +00:00
Notify(result HookResult) error
}
var notifier Notifier
2022-05-26 07:05:49 +00:00
// Notify is the global method to notify hook result
func Notify(result HookResult) {
if notifier == nil {
return
}
2022-05-26 07:05:49 +00:00
if err := notifier.Notify(result); err != nil {
logger.Error.Printf("unable to send notification for webhook %s#%d: %v\n", result.Name(), result.ID(), err)
}
}
// Init creates the notifier singleton regarding the URI.
func Init(uri string) (err error) {
notifier, err = NewNotifier(uri)
return err
}