лаба 4 на оценку 5

This commit is contained in:
2026-10-30 12:27:49 +03:00
parent 7860d81fa1
commit f9444a3965
59 changed files with 4696 additions and 90 deletions
+36 -1
View File
@@ -11,6 +11,8 @@ import (
"time"
cacheadapter "mtusi2026lab4/internal/adapter/cache"
"mtusi2026lab4/internal/adapter/health"
"mtusi2026lab4/internal/adapter/objectstore"
"mtusi2026lab4/internal/adapter/postgres"
redisadapter "mtusi2026lab4/internal/adapter/redis"
"mtusi2026lab4/internal/application"
@@ -43,6 +45,25 @@ func main() {
databasePool,
cfg.DatabaseQueryTimeout,
)
minioStore, err := objectstore.NewMinIOStore(
cfg.S3Endpoint,
cfg.S3Region,
cfg.S3Bucket,
cfg.S3AccessKeyID,
cfg.S3SecretAccessKey,
cfg.S3OperationTimeout,
)
if err != nil {
log.Fatalf("[FATAL] Invalid object storage configuration: %v", err)
}
storageContext, storageCancel := context.WithTimeout(
context.Background(),
cfg.S3OperationTimeout,
)
if err = minioStore.Ping(storageContext); err != nil {
log.Printf("[WARN] Object storage unavailable at startup: %v", err)
}
storageCancel()
var applicationStore application.Repository = postgresStore
@@ -90,6 +111,7 @@ func main() {
cursorCodec,
cfg.SessionTTL,
application.WithIdempotencyTTL(cfg.IdempotencyTTL),
application.WithObjectStore(minioStore),
)
if err != nil {
log.Fatalf("[FATAL] Application initialization failed: %v", err)
@@ -98,7 +120,7 @@ func main() {
handler := handlers.NewHandler(
service,
handlers.WithReadiness(
databasePool,
health.NewMultiChecker(databasePool, minioStore),
cfg.ReadinessTimeout,
),
handlers.WithSessionCookieSecure(cfg.SessionCookieSecure),
@@ -107,6 +129,7 @@ func main() {
mux := http.NewServeMux()
mux.HandleFunc("GET /health/live", handler.HealthLive)
mux.HandleFunc("GET /health/lb", handler.HealthLive)
mux.HandleFunc("GET /health/ready", handler.HealthReady)
mux.HandleFunc(
@@ -150,6 +173,18 @@ func main() {
"GET /api/v1/chats/{chat_id}/messages",
requireAuth(handler.GetMessages),
)
mux.HandleFunc(
"POST /api/v1/chats/{chat_id}/attachments",
requireAuth(handler.UploadAttachment),
)
mux.HandleFunc(
"GET /api/v1/attachments/{attachment_id}",
requireAuth(handler.GetAttachment),
)
mux.HandleFunc(
"GET /api/v1/attachments/{attachment_id}/content",
requireAuth(handler.DownloadAttachment),
)
var rootHandler http.Handler = mux
rootHandler = middleware.Recovery(rootHandler)