Init commit

This commit is contained in:
2026-01-27 15:31:58 +03:00
commit e6dc59c266
37 changed files with 1707 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
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...)
}
+40
View File
@@ -0,0 +1,40 @@
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"time"
)
type Runnable func(ctx context.Context) error
func Run(ctx context.Context, runnable ...Runnable) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
errCh := make(chan error, len(runnable))
for _, r := range runnable {
go func(run Runnable) {
if err := run(ctx); err != nil {
errCh <- err
}
}(r)
}
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
select {
case sig := <-sigCh:
log.Println("shutdown signal:", sig)
case err := <-errCh:
log.Println("runtime error:", err)
}
cancel()
time.Sleep(2 * time.Second)
}