Introduce configuration validation, Postgres migrations, Redis/storage adapters, and the seed sample video.
20 lines
361 B
Go
20 lines
361 B
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
func Connect(ctx context.Context, url string) (*pgxpool.Pool, error) {
|
|
pool, err := pgxpool.New(ctx, url)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("connect db: %w", err)
|
|
}
|
|
if err := pool.Ping(ctx); err != nil {
|
|
return nil, fmt.Errorf("ping db: %w", err)
|
|
}
|
|
return pool, nil
|
|
}
|