chore: Fix golangci-lint configuration and patch errors (#34)

* chore: Fix golangci-lint configuration and patch errors

Due to misconfiguration of a linting rules directory, our linter has not been
working properly. This change fixes the configuration issue, and all remaining
linting errors.

* Fix race in peer logging

* Fix race and return

* Lock on bufferred amount low

* Fix mutex lock
This commit is contained in:
Kyle Carberry
2022-01-20 10:00:13 -06:00
committed by GitHub
parent 6a919aea79
commit 2654a93132
38 changed files with 283 additions and 255 deletions

View File

@ -21,7 +21,7 @@ import (
type Store interface {
querier
InTx(context.Context, func(Store) error) error
InTx(func(Store) error) error
}
// DBTX represents a database connection or transaction.
@ -46,16 +46,16 @@ type sqlQuerier struct {
}
// InTx performs database operations inside a transaction.
func (q *sqlQuerier) InTx(ctx context.Context, fn func(Store) error) error {
func (q *sqlQuerier) InTx(function func(Store) error) error {
if q.sdb == nil {
return nil
}
tx, err := q.sdb.Begin()
transaction, err := q.sdb.Begin()
if err != nil {
return xerrors.Errorf("begin transaction: %w", err)
}
defer func() {
rerr := tx.Rollback()
rerr := transaction.Rollback()
if rerr == nil || errors.Is(rerr, sql.ErrTxDone) {
// no need to do anything, tx committed successfully
return
@ -63,11 +63,11 @@ func (q *sqlQuerier) InTx(ctx context.Context, fn func(Store) error) error {
// couldn't roll back for some reason, extend returned error
err = xerrors.Errorf("defer (%s): %w", rerr.Error(), err)
}()
err = fn(&sqlQuerier{db: tx})
err = function(&sqlQuerier{db: transaction})
if err != nil {
return xerrors.Errorf("execute transaction: %w", err)
}
err = tx.Commit()
err = transaction.Commit()
if err != nil {
return xerrors.Errorf("commit transaction: %w", err)
}