diff --git a/main.go b/main.go index e295c58..6d04cda 100644 --- a/main.go +++ b/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() + }