diff --git a/cmd/evening_detective_server/main.go b/cmd/evening_detective_server/main.go index 056ea42..51a7675 100644 --- a/cmd/evening_detective_server/main.go +++ b/cmd/evening_detective_server/main.go @@ -18,6 +18,7 @@ import ( "evening_detective_server/internal/repos/game_map_repo" "evening_detective_server/internal/repos/game_reviews_repo" "evening_detective_server/internal/repos/games_repo" + "evening_detective_server/internal/repos/health_repo" "evening_detective_server/internal/repos/refresh_tokens_repo" "evening_detective_server/internal/repos/scenarios_repo" "evening_detective_server/internal/repos/screen_sessions_repo" @@ -84,11 +85,8 @@ func main() { log.Fatalf("Unable to create connection pool: %v\n", err) } defer dbpool.Close() - - // Test request to DB - var greeting string - if err = dbpool.QueryRow(context.Background(), "select 'Hello, world!'").Scan(&greeting); err != nil { - log.Fatalf("QueryRow failed: %v\n", err) + if err := health_repo.New(dbpool).Check(context.Background()); err != nil { + log.Fatalf("database check failed: %v\n", err) } usersRepo := users_repo.NewUserRepo(dbpool) diff --git a/internal/repos/health_repo/repo.go b/internal/repos/health_repo/repo.go new file mode 100644 index 0000000..41caabd --- /dev/null +++ b/internal/repos/health_repo/repo.go @@ -0,0 +1,19 @@ +package health_repo + +import ( + "context" + + "github.com/jackc/pgx/v5/pgxpool" +) + +type Repo struct { + pool *pgxpool.Pool +} + +func New(pool *pgxpool.Pool) *Repo { + return &Repo{pool: pool} +} + +func (r *Repo) Check(ctx context.Context) error { + return r.pool.Ping(ctx) +}