-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (35 loc) · 815 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
41
42
43
44
45
46
47
48
package main
import (
"os"
"tg-alerter/bot"
"tg-alerter/logger"
"github.com/joho/godotenv"
)
var TG_TOKEN_VAR_NAME = "TG_API_BOT_TOKEN"
func main() {
log := logger.InitLogger()
botToken := getBotToken()
if botToken == "" {
log.Fatalf("No %s provided", TG_TOKEN_VAR_NAME)
}
myBot, err := bot.NewBot(botToken)
if err != nil {
log.Fatalf("Error creating bot: %v", err)
}
if err := myBot.Start(); err != nil {
log.Fatalf("Error starting bot: %v", err)
}
log.Warn("ЭТО МЫ В MAIN ПОСЛЕ .START()")
}
func getBotToken() string {
log := logger.GetLogger()
botToken := os.Getenv(TG_TOKEN_VAR_NAME)
if botToken == "" {
err := godotenv.Load(".env")
if err != nil {
log.Error("Failed loading .env: ", err)
}
botToken = os.Getenv(TG_TOKEN_VAR_NAME)
}
return botToken
}