-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (36 loc) · 884 Bytes
/
main.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
36
37
38
39
40
package main
import (
bot "github.com/amitizle/go-boker-tov-bot/internal/telegram_bot"
"github.com/spf13/viper"
"log"
"strings"
)
var (
mandatoryConfig = []string{
"THE_CAT_API_KEY",
"TELEGRAM_BOT_TOKEN",
"TELEGRAM_BOT_WEBHOOK",
}
envVarPrefix = "BOKER_TOV"
)
func main() {
configureBot()
config := bot.New()
config.TelegramBotToken = viper.GetString("TELEGRAM_BOT_TOKEN")
config.WebhookAddress = viper.GetString("TELEGRAM_BOT_WEBHOOK")
bot.Start(config)
}
func configureBot() {
viper.AutomaticEnv()
viper.SetEnvPrefix(envVarPrefix)
missingConfigKeys := []string{}
for _, k := range mandatoryConfig {
if !viper.IsSet(k) {
missingConfigKeys = append(missingConfigKeys, k)
}
}
if len(missingConfigKeys) > 0 {
log.Fatalf("Cannot start bot, missing %d mandatory config keys: %s",
len(missingConfigKeys), strings.Join(missingConfigKeys, ", "))
}
}