From aefcc932fd4e23dda62392a41a154aac6bebd44c Mon Sep 17 00:00:00 2001 From: UnAfraid Date: Sun, 22 Oct 2023 16:02:49 +0300 Subject: [PATCH] bbolt transaction scoper cleanup --- main.go | 3 +-- pkg/dbx/bbolt_transaction_scoper.go | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index e3162de..bd7283e 100644 --- a/main.go +++ b/main.go @@ -96,7 +96,7 @@ func main() { return } - transactionScoper := dbx.NewBBoltTransactionScope(db) + transactionScoper := dbx.NewBBoltTransactionScoper(db) subscriptionImpl := subscription.NewInMemorySubscription() serverRepository := bbolt.NewServerRepository(db) @@ -115,7 +115,6 @@ func main() { } var wireguardBackend backend.Backend - switch strings.ToLower(conf.Backend) { case "linux": wireguardBackend, err = linux.NewLinuxBackend() diff --git a/pkg/dbx/bbolt_transaction_scoper.go b/pkg/dbx/bbolt_transaction_scoper.go index e6d6df3..97bf7ec 100644 --- a/pkg/dbx/bbolt_transaction_scoper.go +++ b/pkg/dbx/bbolt_transaction_scoper.go @@ -11,18 +11,18 @@ type contextKey struct{ name string } var bboltTxKey = contextKey{name: "bboltTxKey"} -type bboltTransactionScope struct { +type bboltTransactionScoper struct { db *bbolt.DB } -func NewBBoltTransactionScope(db *bbolt.DB) TransactionScoper { - return &bboltTransactionScope{ +func NewBBoltTransactionScoper(db *bbolt.DB) TransactionScoper { + return &bboltTransactionScoper{ db: db, } } -func (txScope *bboltTransactionScope) InTransactionScope(ctx context.Context, transactionScope func(ctx context.Context) error) (err error) { - return InBBoltTransactionScope(ctx, txScope.db, func(ctx context.Context, tx *bbolt.Tx) error { +func (bts *bboltTransactionScoper) InTransactionScope(ctx context.Context, transactionScope func(ctx context.Context) error) (err error) { + return InBBoltTransactionScope(ctx, bts.db, func(ctx context.Context, tx *bbolt.Tx) error { return transactionScope(ctx) }) }