backend barebone done, big chunk of work done
This commit is contained in:
+26
-4
@@ -13,9 +13,14 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"messenger/internal/auth"
|
||||
"messenger/internal/platform/config"
|
||||
"messenger/internal/platform/logger"
|
||||
"messenger/internal/realtime"
|
||||
"messenger/internal/server"
|
||||
"messenger/internal/store"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -27,7 +32,27 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
httpServer := server.New(cfg, log)
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
pool, err := pgxpool.New(ctx, cfg.DatabaseURL)
|
||||
if err != nil {
|
||||
log.Error("failed to create db pool", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
st := store.New(pool)
|
||||
if err := st.Migrate(ctx); err != nil {
|
||||
log.Error("database migration failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
log.Info("database ready")
|
||||
|
||||
tm := auth.NewTokenManager(cfg.JWTSecret)
|
||||
hub := realtime.NewHub(st)
|
||||
|
||||
httpServer := server.New(cfg, log, st, tm, hub)
|
||||
|
||||
// Run the server in a goroutine so that shutdown can be triggered
|
||||
// from the signal handler below.
|
||||
@@ -44,9 +69,6 @@ func main() {
|
||||
}()
|
||||
|
||||
// Wait for a termination signal, then drain in-flight requests.
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
<-ctx.Done()
|
||||
log.Info("shutting down")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user