forked from mtusi2026/mtusi2026lab3
feat(app) lab 3 implemented
This commit is contained in:
+18
-9
@@ -1,3 +1,5 @@
|
||||
// Command server starts the messenger HTTP API, applies optional migrations,
|
||||
// and shuts down gracefully on SIGINT/SIGTERM.
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -8,10 +10,10 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal"
|
||||
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/config"
|
||||
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/database"
|
||||
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/session"
|
||||
"gitflic.ru/project/bulla-max/mtusi2026lab/internal"
|
||||
"gitflic.ru/project/bulla-max/mtusi2026lab/internal/config"
|
||||
"gitflic.ru/project/bulla-max/mtusi2026lab/internal/database"
|
||||
"gitflic.ru/project/bulla-max/mtusi2026lab/internal/session"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -29,11 +31,18 @@ func main() {
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
migrateCtx, cancelMigrate := context.WithTimeout(rootCtx, 60*time.Second)
|
||||
err = database.Migrate(migrateCtx, pool, cfg.DatabaseURL)
|
||||
cancelMigrate()
|
||||
if err != nil {
|
||||
log.Fatalf("migrations: %v", err)
|
||||
if cfg.MigrateOnly || cfg.RunMigrations {
|
||||
migrateCtx, cancelMigrate := context.WithTimeout(rootCtx, 60*time.Second)
|
||||
err = database.Migrate(migrateCtx, pool, cfg.DatabaseURL)
|
||||
cancelMigrate()
|
||||
if err != nil {
|
||||
log.Fatalf("migrations: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.MigrateOnly {
|
||||
log.Printf("migrations applied; migrate-only process exiting")
|
||||
return
|
||||
}
|
||||
|
||||
sessions, err := session.New(cfg.CacheURL, cfg.SessionTTL, cfg.RedisTimeout)
|
||||
|
||||
Reference in New Issue
Block a user