forked from mtusi2026/mtusi2026lab3
refactor: разделил приложение на domain application adapters и HTTP DTO
This commit is contained in:
+20
-9
@@ -10,10 +10,12 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
applicationCache "mtusi2026lab3/internal/cache"
|
||||
cacheadapter "mtusi2026lab3/internal/adapter/cache"
|
||||
"mtusi2026lab3/internal/adapter/postgres"
|
||||
redisadapter "mtusi2026lab3/internal/adapter/redis"
|
||||
"mtusi2026lab3/internal/application"
|
||||
"mtusi2026lab3/internal/config"
|
||||
"mtusi2026lab3/internal/database"
|
||||
"mtusi2026lab3/internal/store"
|
||||
"mtusi2026lab3/internal/transport/http/handlers"
|
||||
"mtusi2026lab3/internal/transport/http/middleware"
|
||||
)
|
||||
@@ -37,15 +39,15 @@ func main() {
|
||||
}
|
||||
defer databasePool.Close()
|
||||
|
||||
postgresStore := store.NewPostgreSQLStore(
|
||||
postgresStore := postgres.NewPostgreSQLStore(
|
||||
databasePool,
|
||||
cfg.DatabaseQueryTimeout,
|
||||
)
|
||||
|
||||
var applicationStore store.Repository = postgresStore
|
||||
var applicationStore application.Repository = postgresStore
|
||||
|
||||
if cfg.RedisURL != "" {
|
||||
redisChatCache, cacheError := applicationCache.NewRedisChatCache(
|
||||
redisChatCache, cacheError := redisadapter.NewRedisChatCache(
|
||||
cfg.RedisURL,
|
||||
cfg.RedisCacheTTL,
|
||||
cfg.RedisOperationTimeout,
|
||||
@@ -71,20 +73,29 @@ func main() {
|
||||
}
|
||||
cacheCancel()
|
||||
|
||||
applicationStore = store.NewCachedRepository(
|
||||
applicationStore = cacheadapter.NewCachedRepository(
|
||||
postgresStore,
|
||||
redisChatCache,
|
||||
log.Default(),
|
||||
)
|
||||
}
|
||||
|
||||
cursorCodec, err := application.NewCursorCodec(cfg.CursorSigningKey)
|
||||
if err != nil {
|
||||
log.Fatalf("[FATAL] Invalid cursor configuration: %v", err)
|
||||
}
|
||||
|
||||
service, err := application.NewService(applicationStore, cursorCodec, cfg.SessionTTL)
|
||||
if err != nil {
|
||||
log.Fatalf("[FATAL] Application initialization failed: %v", err)
|
||||
}
|
||||
|
||||
handler := handlers.NewHandler(
|
||||
applicationStore,
|
||||
service,
|
||||
handlers.WithReadiness(
|
||||
databasePool,
|
||||
cfg.ReadinessTimeout,
|
||||
),
|
||||
handlers.WithSessionTTL(cfg.SessionTTL),
|
||||
)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
@@ -100,7 +111,7 @@ func main() {
|
||||
mux.HandleFunc("POST /api/v1/users", handler.CreateUser)
|
||||
|
||||
requireAuth := func(next http.HandlerFunc) http.HandlerFunc {
|
||||
return middleware.RequireAuth(postgresStore, next)
|
||||
return middleware.RequireAuth(service, next)
|
||||
}
|
||||
|
||||
mux.HandleFunc(
|
||||
|
||||
Reference in New Issue
Block a user