notifier.go 593 B

12345678910111213141516171819202122232425262728
  1. package notification
  2. import (
  3. "log/slog"
  4. )
  5. // Notifier is able to send a notification.
  6. type Notifier interface {
  7. Notify(result HookResult) error
  8. }
  9. var notifier Notifier
  10. // Notify is the global method to notify hook result
  11. func Notify(result HookResult) {
  12. if notifier == nil {
  13. return
  14. }
  15. if err := notifier.Notify(result); err != nil {
  16. slog.Error("unable to send notification", "webhook", result.Name(), "id", result.ID(), "err", err)
  17. }
  18. }
  19. // Init creates the notifier singleton regarding the URI.
  20. func Init(uri string) (err error) {
  21. notifier, err = NewNotifier(uri)
  22. return err
  23. }