-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
50 lines (40 loc) · 1.02 KB
/
init.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
49
50
package main
import (
"fmt"
"log"
"github.com/emaele/rss-telegram-notifier/entities"
"github.com/emaele/rss-telegram-notifier/types"
tg "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/mmcdole/gofeed"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func initBackstore() (b Backstore) {
configuration := readVars()
feedParser := gofeed.NewParser()
var err error
connstring := fmt.Sprintf(types.Mariadbdsn, configuration.DBUser, configuration.DBPassword, configuration.DBHost, configuration.DBPort, configuration.DBName)
db, err := gorm.Open(mysql.Open(connstring), &gorm.Config{})
if err != nil {
log.Panic(err)
}
err = db.AutoMigrate(&entities.RssFeed{})
if err != nil {
log.Panic(err)
}
err = db.AutoMigrate(&entities.RssItem{})
if err != nil {
log.Panic(err)
}
// initializing telegram bot
bot, err := tg.NewBotAPI(configuration.TelegramToken)
if err != nil {
log.Panic(err)
}
return Backstore{
conf: &configuration,
bot: bot,
feedparser: feedParser,
db: db,
}
}