Moved bot and webserver to goroutines
This commit is contained in:
parent
3a962cc8a3
commit
5eebacceea
29
main.go
29
main.go
|
@ -2,13 +2,14 @@ package main
|
|||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"nefrace.ru/doomer/config"
|
||||
"nefrace.ru/doomer/db"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config.InitConfig()
|
||||
cfg := config.InitConfig()
|
||||
db, err := db.NewDatabase()
|
||||
if err != nil {
|
||||
log.Fatalf("Cant open database: %v", err)
|
||||
|
@ -17,10 +18,24 @@ func main() {
|
|||
defer db.Close()
|
||||
doomer := NewDoomer(db)
|
||||
|
||||
dp := NewDispatcher(doomer)
|
||||
app := InitServer(":3000")
|
||||
go func() {
|
||||
log.Fatal(app.Run())
|
||||
}()
|
||||
log.Println(dp.Poll())
|
||||
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()
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue