This commit is contained in:
2026-10-01 15:52:29 +07:00
parent cd49b9164b
commit f8d78b04ff
2 changed files with 22 additions and 5 deletions
+3 -5
View File
@@ -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)
+19
View File
@@ -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)
}