-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifier.go
35 lines (27 loc) · 845 Bytes
/
notifier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"log"
"github.com/spf13/viper"
)
// Notifier encapsulates the logic and infrastructure necessary to send
// notifications to external systems.
type Notifier interface {
Notify(msg string) error
}
// NoopNotifier simply performs a no-op instead of notifying any external system.
type NoopNotifier struct{}
// Notify returns nil immediately.
func (n *NoopNotifier) Notify(msg string) error {
return nil
}
// NewNotifier builds a notifier based on the current configuration, or a NoopNotifier
// if none configured.
func NewNotifier() Notifier {
token := viper.GetString("telegram.bot_token")
chatID := viper.GetString("telegram.chat_id")
if token == "" || chatID == "" {
log.Println("🟨 No notifier configured, using NoopNotifier.")
return &NoopNotifier{}
}
return NewTelegramNotifier(token, chatID)
}