44 lines
898 B
Go
44 lines
898 B
Go
package main
|
|
|
|
import (
|
|
"GoFinanceManager/src/api"
|
|
"GoFinanceManager/src/bot"
|
|
"GoFinanceManager/src/config"
|
|
|
|
"context"
|
|
"log"
|
|
)
|
|
|
|
func main() {
|
|
var runnable []Runnable
|
|
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
if cfg.RunMode == config.API || cfg.RunMode == config.Standalone {
|
|
server := api.NewServer(cfg)
|
|
runnable = append(runnable, func(ctx context.Context) error {
|
|
log.Println("API started on", cfg.APIPort)
|
|
return server.Start()
|
|
})
|
|
runnable = append(runnable, func(ctx context.Context) error {
|
|
<-ctx.Done()
|
|
return server.Shutdown(context.Background())
|
|
})
|
|
}
|
|
|
|
if cfg.RunMode == config.Bot || cfg.RunMode == config.Standalone {
|
|
tgBot, _ := bot.NewBot(cfg)
|
|
log.Println("Bot started...")
|
|
runnable = append(runnable, func(ctx context.Context) error {
|
|
return tgBot.Start(ctx)
|
|
})
|
|
}
|
|
|
|
Run(ctx, runnable...)
|
|
}
|