mirror of
https://github.com/ncarlier/webhookd.git
synced 2025-04-07 20:41:49 +00:00
29 lines
633 B
Go
29 lines
633 B
Go
package notification
|
|
|
|
import (
|
|
"github.com/ncarlier/webhookd/pkg/logger"
|
|
)
|
|
|
|
// Notifier is able to send a notification.
|
|
type Notifier interface {
|
|
Notify(result HookResult) error
|
|
}
|
|
|
|
var notifier Notifier
|
|
|
|
// Notify is the global method to notify hook result
|
|
func Notify(result HookResult) {
|
|
if notifier == nil {
|
|
return
|
|
}
|
|
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
|
|
}
|