Skip to content

Commit

Permalink
chore: fix all lint
Browse files Browse the repository at this point in the history
  • Loading branch information
flemzord committed Nov 7, 2023
1 parent 69536ca commit 23fc59a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 36 deletions.
5 changes: 3 additions & 2 deletions components/ledger/internal/api/bulk/bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/formancehq/ledger/internal"
"math/big"

ledger "github.com/formancehq/ledger/internal"
"github.com/formancehq/ledger/internal/api/backend"
"github.com/formancehq/ledger/internal/api/shared"
"github.com/formancehq/ledger/internal/engine/command"
"github.com/formancehq/stack/libs/go-libs/metadata"
"math/big"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion components/ledger/internal/api/v2/controllers_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package v2

import (
"encoding/json"
"net/http"

"github.com/formancehq/ledger/internal/api/bulk"
"github.com/formancehq/ledger/internal/api/shared"
sharedapi "github.com/formancehq/stack/libs/go-libs/api"
"net/http"
)

func bulkHandler(w http.ResponseWriter, r *http.Request) {
Expand Down
13 changes: 7 additions & 6 deletions components/ledger/internal/api/v2/controllers_bulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ package v2_test
import (
"bytes"
"fmt"
"math/big"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"

ledger "github.com/formancehq/ledger/internal"
"github.com/formancehq/ledger/internal/api/backend"
"github.com/formancehq/ledger/internal/api/bulk"
Expand All @@ -14,12 +21,6 @@ import (
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"math/big"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"
)

func TestBulk(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package v2_test
import (
"bytes"
"fmt"
"github.com/formancehq/ledger/internal/api/shared"
"math/big"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"

"github.com/formancehq/ledger/internal/api/shared"

ledger "github.com/formancehq/ledger/internal"
v2 "github.com/formancehq/ledger/internal/api/v2"
"github.com/formancehq/ledger/internal/engine/command"
Expand Down
5 changes: 3 additions & 2 deletions components/ledger/internal/api/v2/utils.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package v2

import (
"io"
"net/http"

ledger "github.com/formancehq/ledger/internal"
"github.com/formancehq/ledger/internal/storage/ledgerstore"
"github.com/formancehq/stack/libs/go-libs/collectionutils"
"github.com/formancehq/stack/libs/go-libs/pointer"
"github.com/formancehq/stack/libs/go-libs/query"
"io"
"net/http"
)

func getPITFilter(r *http.Request) (*ledgerstore.PITFilter, error) {
Expand Down
35 changes: 14 additions & 21 deletions components/ledger/internal/engine/command/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sync/atomic"
"time"

"github.com/formancehq/ledger/pkg/opentelemetry/metrics"
"github.com/formancehq/stack/libs/go-libs/collectionutils"
"github.com/formancehq/stack/libs/go-libs/logging"
"github.com/pkg/errors"
Expand All @@ -33,10 +32,9 @@ type Accounts struct {
}

type lockIntent struct {
accounts Accounts
acquired chan struct{}
at time.Time
metricRegistry metrics.PerLedgerRegistry
accounts Accounts
acquired chan struct{}
at time.Time
}

func (intent *lockIntent) tryLock(ctx context.Context, chain *DefaultLocker) bool {
Expand Down Expand Up @@ -73,8 +71,6 @@ func (intent *lockIntent) tryLock(ctx context.Context, chain *DefaultLocker) boo
chain.writeLocks[account] = struct{}{}
}

intent.metricRegistry.LockWaitingTime().Record(ctx, time.Since(intent.at).Milliseconds())

return true
}

Expand All @@ -92,11 +88,10 @@ func (intent *lockIntent) unlock(ctx context.Context, chain *DefaultLocker) {
}

type DefaultLocker struct {
intents *collectionutils.LinkedList[*lockIntent]
mu sync.Mutex
readLocks map[string]*atomic.Int64
writeLocks map[string]struct{}
perLedgerRegistry metrics.PerLedgerRegistry
intents *collectionutils.LinkedList[*lockIntent]
mu sync.Mutex
readLocks map[string]*atomic.Int64
writeLocks map[string]struct{}
}

func (defaultLocker *DefaultLocker) Lock(ctx context.Context, accounts Accounts) (Unlock, error) {
Expand All @@ -110,10 +105,9 @@ func (defaultLocker *DefaultLocker) Lock(ctx context.Context, accounts Accounts)

logger.Debugf("Intent lock")
intent := &lockIntent{
accounts: accounts,
acquired: make(chan struct{}),
at: time.Now(),
metricRegistry: defaultLocker.perLedgerRegistry,
accounts: accounts,
acquired: make(chan struct{}),
at: time.Now(),
}

recheck := func() {
Expand Down Expand Up @@ -160,11 +154,10 @@ func (defaultLocker *DefaultLocker) Lock(ctx context.Context, accounts Accounts)
}
}

func NewDefaultLocker(perLedgerRegistry metrics.PerLedgerRegistry) *DefaultLocker {
func NewDefaultLocker() *DefaultLocker {
return &DefaultLocker{
intents: collectionutils.NewLinkedList[*lockIntent](),
readLocks: map[string]*atomic.Int64{},
writeLocks: map[string]struct{}{},
perLedgerRegistry: perLedgerRegistry,
intents: collectionutils.NewLinkedList[*lockIntent](),
readLocks: map[string]*atomic.Int64{},
writeLocks: map[string]struct{}{},
}
}
3 changes: 1 addition & 2 deletions components/ledger/internal/engine/command/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"testing"
"time"

"github.com/formancehq/ledger/pkg/opentelemetry/metrics"
"github.com/formancehq/stack/libs/go-libs/logging"
"github.com/stretchr/testify/require"
)

func TestLock(t *testing.T) {
locker := NewDefaultLocker(metrics.NewNoOpRegistry())
locker := NewDefaultLocker()
var accounts []string
for i := 0; i < 10; i++ {
accounts = append(accounts, fmt.Sprintf("accounts:%d", i))
Expand Down
1 change: 1 addition & 0 deletions components/ledger/internal/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ledger

import (
"fmt"

"github.com/formancehq/stack/libs/go-libs/metadata"
)

Expand Down
3 changes: 2 additions & 1 deletion components/ledger/internal/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package ledger

import (
"fmt"
"github.com/pkg/errors"
"math/big"

"github.com/pkg/errors"

"github.com/formancehq/stack/libs/go-libs/metadata"
)

Expand Down

0 comments on commit 23fc59a

Please sign in to comment.