1
0
Fork 0

feat: add postgres repository for training

This commit is contained in:
Vojtěch Mareš 2024-06-23 10:35:38 +02:00
parent 8c277ef692
commit ff7e320481
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
19 changed files with 1277 additions and 414 deletions

View file

@ -3,6 +3,7 @@ package server
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
"time"
fiberzap "github.com/gofiber/contrib/fiberzap/v2"
@ -16,13 +17,15 @@ type Server struct {
port int
logger *zap.Logger
apiHandlers *APIHandlers
pool *pgxpool.Pool
}
func NewServer(apiHandlers *APIHandlers, port int, logger *zap.Logger) *Server {
func NewServer(apiHandlers *APIHandlers, port int, logger *zap.Logger, pool *pgxpool.Pool) *Server {
return &Server{
apiHandlers: apiHandlers,
port: port,
logger: logger,
pool: pool,
}
}
@ -54,6 +57,11 @@ func (s *Server) Run(ctx context.Context) {
panic(err)
}
// gracefully shutdown/close database pool
if s.pool != nil {
s.pool.Close()
}
s.logger.Info("HTTP server shut down gracefully.", zap.Duration("duration", time.Since(shutdownBegan)))
}