doomer/main.go

42 lines
622 B
Go

package main
import (
"log"
"sync"
"nefrace.ru/doomer/config"
"nefrace.ru/doomer/db"
)
func main() {
cfg := config.InitConfig()
db, err := db.NewDatabase()
if err != nil {
log.Fatalf("Cant open database: %v", err)
}
defer db.Close()
doomer := NewDoomer(db)
var wg sync.WaitGroup
if cfg.Telegram.Token != "" {
wg.Add(1)
log.Println("Starting telegram bot")
go func() {
defer wg.Done()
dp := NewDispatcher(doomer)
log.Println(dp.Poll())
}()
}
if cfg.Host != "" {
wg.Add(1)
go func() {
defer wg.Done()
app := InitServer(cfg.Host)
log.Fatal(app.Run())
}()
}
wg.Wait()
}