парсер

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,38 @@
package transaction
import (
"context"
"errors"
"fmt"
"github.com/jackc/pgx/v5"
"github.com/rs/zerolog/log"
)
func Wrap(ctx context.Context, fn func(context.Context) error) error {
tx, err := pool.Begin(ctx)
if err != nil {
return fmt.Errorf("pool.Begin: %w", err)
}
defer func() {
err = tx.Rollback(ctx)
if err != nil && !errors.Is(err, pgx.ErrTxClosed) {
log.Error().Err(err).Msg("transaction: Rollback")
}
}()
ctx = context.WithValue(ctx, ctxKey{}, &Transaction{tx})
err = fn(ctx)
if err != nil {
return fmt.Errorf("fn: %w", err)
}
err = tx.Commit(ctx)
if err != nil {
return fmt.Errorf("tx.Commit: %w", err)
}
return nil
}