feat: add postgres repository for training
This commit is contained in:
parent
8c277ef692
commit
ff7e320481
19 changed files with 1277 additions and 414 deletions
|
|
@ -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)))
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue