diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 5ed9062..79294b8 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -16,8 +16,8 @@ jobs: go-version: stable - name: Run linter - uses: golangci/golangci-lint-action@v3.5.0 # Action page: + uses: golangci/golangci-lint-action@v3.6.0 # Action page: with: - version: v1.52 # without patch version + version: v1.53 # without patch version only-new-issues: false # show only new issues if it's a pull request args: --timeout=10m --build-tags=race diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..bd21647 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,86 @@ +# Documentation: + +run: + timeout: 1m + skip-dirs: + - .github + - .git + allow-parallel-runners: true + +output: + format: colored-line-number # colored-line-number|line-number|json|tab|checkstyle|code-climate + +linters-settings: + wsl: + allow-assign-and-anything: true + govet: + check-shadowing: true + golint: + min-confidence: 0.1 + gocyclo: + min-complexity: 15 + godot: + scope: declarations + capital: true + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 3 + misspell: + locale: US + lll: + line-length: 120 + prealloc: + simple: true + range-loops: true + for-loops: true + nolintlint: + allow-leading-space: false + require-specific: true + +linters: # All available linters list: + disable-all: true + enable: + - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers + - bodyclose # Checks whether HTTP response body is closed successfully + - dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) + - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases + - errorlint # find code that will cause problems with the error wrapping scheme introduced in Go 1.13 + - exhaustive # check exhaustiveness of enum switch statements + - exportloopref # checks for pointers to enclosing loop variables + - gochecknoglobals # Checks that no globals are present in Go code + - gochecknoinits # Checks that no init functions are present in Go code + - goconst # Finds repeated strings that could be replaced by a constant + - gocritic # The most opinionated Go source code linter + - gocyclo # Computes and checks the cyclomatic complexity of functions + - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification + - goimports # Goimports does everything that gofmt does. Additionally it checks unused imports + - revive + - goprintffuncname # Checks that printf-like functions are named with `f` at the end + - gosec # Inspects source code for security problems + - gosimple # Linter for Go source code that specializes in simplifying a code + - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string + - ineffassign # Detects when assignments to existing variables are not used + - misspell # Finds commonly misspelled English words in comments + - nakedret # Finds naked returns in functions greater than a specified function length + - noctx # finds sending http request without context.Context + - nolintlint # Reports ill-formed or insufficient nolint directives + - prealloc # Finds slice declarations that could potentially be preallocated + - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks + - stylecheck # Stylecheck is a replacement for golint + - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes + - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code + - unconvert # Remove unnecessary type conversions + - unparam # Reports unused function parameters + - unused # Checks Go code for unused constants, variables, functions and types + - whitespace # Tool for detection of leading and trailing whitespace + +issues: + exclude-rules: + - path: _test\.go + linters: + - dupl + - funlen + - scopelint + - gocognit diff --git a/go.mod b/go.mod index 01bc1d9..df9a645 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/roadrunner-server/lock/v4 go 1.20 require ( - github.com/roadrunner-server/sdk/v4 v4.2.6 + github.com/roadrunner-server/sdk/v4 v4.3.0 go.buf.build/protocolbuffers/go/roadrunner-server/api v1.3.39 go.uber.org/zap v1.24.0 ) diff --git a/go.sum b/go.sum index 0293d6a..0499890 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,5 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= @@ -8,10 +7,9 @@ github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/roadrunner-server/sdk/v4 v4.2.6 h1:BSQ+HHklszJKGCo91jqRwvgjhSkuz097cbPHMFAhIfo= -github.com/roadrunner-server/sdk/v4 v4.2.6/go.mod h1:WBLEsz9EMY6CkwpdeageMEPLevD/PaUf4rOOsBsaKlo= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/roadrunner-server/sdk/v4 v4.3.0 h1:QdCK5kd/eLTnyLQsOOFtkd3CQK+NR4j/5PF5OpeHvA0= +github.com/roadrunner-server/sdk/v4 v4.3.0/go.mod h1:7LIxYOBo306SncMKUxEy9Xd3GQWYHW0G4zuDHnKZ3l4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= go.buf.build/protocolbuffers/go/roadrunner-server/api v1.3.39 h1:WZ2k78qL9izK0ik1hBRZ3vwXX64D1YAgHdYMzpTvShE= go.buf.build/protocolbuffers/go/roadrunner-server/api v1.3.39/go.mod h1:CfIAvR+W2N+Y0WXMzwT80Eh83CmBPWplgFQDA5HftC4= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= diff --git a/item.go b/item.go index a2c158f..a139509 100644 --- a/item.go +++ b/item.go @@ -33,6 +33,11 @@ func (i item) ID() string { return i.id } +// TODO: use resource as GroupID +func (i item) GroupID() string { + return "" +} + func (i item) TTL() int { return i.ttl } diff --git a/locker.go b/locker.go index 761d630..32b4b91 100644 --- a/locker.go +++ b/locker.go @@ -27,12 +27,12 @@ type locker struct { // used in the CAS algorithm to check if we have mutex acquired locked *int64 queue *pq.BinHeap[item] - mu sync.Mutex // + mu sync.Mutex - resources sync.Map //map[string]*res + resources sync.Map // map[string]*res } -func NewLocker(log *zap.Logger) *locker { +func newLocker(log *zap.Logger) *locker { l := &locker{ queue: pq.NewBinHeap[item](1000), log: log, diff --git a/plugin.go b/plugin.go index 5998d80..64c498d 100644 --- a/plugin.go +++ b/plugin.go @@ -20,7 +20,7 @@ type Plugin struct { func (p *Plugin) Init(log Logger) error { p.log = log.NamedLogger(pluginName) - p.locks = NewLocker(p.log) + p.locks = newLocker(p.log) return nil }