Реализация на 5

This commit is contained in:
Grbisba
2026-11-06 13:11:04 +03:00
parent 8d44c74535
commit 711754bbcd
27 changed files with 5999 additions and 116 deletions
+13 -5
View File
@@ -10,9 +10,11 @@ import (
"time"
"gitea.privcloud.tech/mtusi2026/internal/adapter/controller/http"
"gitea.privcloud.tech/mtusi2026/internal/adapter/repository/cache/outside"
"gitea.privcloud.tech/mtusi2026/internal/adapter/repository/storage"
"gitea.privcloud.tech/mtusi2026/internal/config"
"gitea.privcloud.tech/mtusi2026/internal/pkg/auth/jwtprovider"
"gitea.privcloud.tech/mtusi2026/internal/pkg/cache"
"gitea.privcloud.tech/mtusi2026/internal/pkg/encrypting"
"gitea.privcloud.tech/mtusi2026/internal/pkg/migrator"
"gitea.privcloud.tech/mtusi2026/internal/pkg/postgres"
@@ -39,10 +41,8 @@ func run() error {
return fmt.Errorf("load server config: %w", err)
}
pgx, err := postgres.New(cfg.Postgres)
if err != nil {
return fmt.Errorf("init postgres: %w", err)
}
pgx := postgres.New(cfg.Postgres)
rx := cache.New(cfg)
postgresMigrator := migrator.New(cfg)
tm := txmanager.New(pgx)
provider := jwtprovider.New(cfg)
@@ -53,9 +53,11 @@ func run() error {
refreshTokensRepo := storage.NewRefreshTokensRepo(pgx)
userRepo := storage.NewUsersRepo(pgx)
chatCache := outside.NewChatCache(rx)
authSvc := auth.New(provider, tm, encryptor, userRepo, refreshTokensRepo)
userSvc := user.New(encryptor, userRepo)
chatSvc := chat.New(tm, chatsRepo, messageRepo)
chatSvc := chat.New(tm, chatsRepo, messageRepo, chatCache)
httpRouter := router.New(
middleware.NewAuthMiddleware(authSvc),
@@ -80,6 +82,9 @@ func run() error {
if err = server.Start(ctx); err != nil {
return fmt.Errorf("start HTTP server: %w", err)
}
if err = rx.Start(ctx); err != nil {
slog.Warn("redis unavailable at startup; continuing without cache", "error", err)
}
slog.Info("HTTP server started", "address", cfg.Server.BindAddress())
<-ctx.Done()
@@ -91,6 +96,9 @@ func run() error {
if err = postgresMigrator.Close(shutdownCtx); err != nil {
return fmt.Errorf("close postgres migrator: %w", err)
}
if err = rx.Close(); err != nil {
return fmt.Errorf("close redis: %w", err)
}
return nil
}