парсер

This commit is contained in:
Artem Tsyrulnikov
2026-01-06 21:04:42 +03:00
parent b77e4fd0b6
commit 2c0ae2dfc3
45 changed files with 2202 additions and 51 deletions

View File

@@ -0,0 +1,37 @@
package postgres
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/rs/zerolog/log"
)
type Config struct {
URL string `envconfig:"DB__URL" required:"true"`
}
type Pool struct {
*pgxpool.Pool
}
func New(ctx context.Context, c Config) (*Pool, error) {
cfg, err := pgxpool.ParseConfig(c.URL)
if err != nil {
return nil, fmt.Errorf("pgxpool.ParseConfig: %w", err)
}
pool, err := pgxpool.NewWithConfig(ctx, cfg)
if err != nil {
return nil, fmt.Errorf("pgxpool.NewWithConfig: %w", err)
}
return &Pool{Pool: pool}, nil
}
func (p *Pool) Close() {
p.Pool.Close()
log.Info().Msg("Postgres closed")
}