From b01a28d34668975a34a08e4f4d6063ad260ad764 Mon Sep 17 00:00:00 2001 From: Daniil Suvorov Date: Sun, 12 Jan 2025 16:42:33 +0300 Subject: [PATCH] feat: update golang to 1.22 (#305) --- .gitattributes | 1 + .github/workflows/golangci-lint.yml | 2 +- .github/workflows/test.yml | 2 +- .golangci.yml | 20 ++++- api/api.go | 3 +- api/api_test.go | 2 +- api/oauth/oauth.go | 4 +- callback/callback_test.go | 1 - events/events.go | 112 ---------------------------- go.mod | 2 +- longpoll-bot/longpoll.go | 2 +- longpoll-bot/longpoll_test.go | 2 - longpoll-user/longpoll.go | 4 - longpoll-user/v3/extra.go | 2 +- marusia/cards.go | 4 +- 15 files changed, 30 insertions(+), 133 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..d207b180 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.go text eol=lf diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 2b3ca2a2..d052fedf 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -15,4 +15,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v4 with: - version: v1.56.2 + version: v1.63.4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 796e8315..4e979560 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: test: strategy: matrix: - go-version: [1.21.x, 1.x] + go-version: [1.22.x, 1.x] platform: [ubuntu-latest] runs-on: ${{ matrix.platform }} steps: diff --git a/.golangci.yml b/.golangci.yml index f420e31f..3c698075 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,7 +32,7 @@ linters: - asciicheck - nolintlint - gofumpt - - goerr113 + - err113 - tparallel - errorlint - paralleltest @@ -67,7 +67,7 @@ linters: - gocheckcompilerdirectives - asasalint - - musttag + # - musttag - gosmopolitan - mirror @@ -81,6 +81,18 @@ linters: - wrapcheck + - copyloopvar + - intrange + + - fatcontext + - canonicalheader + + - iface + + - exptostd + - nilnesserr + - usetesting + # - testpackage # TODO: Fix testpackage # - noctx # TODO: Fix noctx @@ -122,6 +134,8 @@ linters: # - protogetter # - spancheck +# - recvcheck # false positive + # depricated # - maligned # - interfacer @@ -159,4 +173,4 @@ linters-settings: testifylint: enable-all: true disable: - - require-error # f func false positive + - require-error # f func false positive diff --git a/api/api.go b/api/api.go index e0c02d42..ddcede1b 100644 --- a/api/api.go +++ b/api/api.go @@ -207,6 +207,7 @@ func buildQuery(sliceParams ...Params) (context.Context, url.Values) { case "access_token": continue case ":context": + //nolint:fatcontext ctx = value.(context.Context) default: query.Set(key, FmtValue(value, 0)) @@ -396,7 +397,7 @@ func fmtReflectValue(value reflect.Value, depth int) string { case reflect.Array, reflect.Slice: s := "" - for i := 0; i < f.Len(); i++ { + for i := range f.Len() { if i > 0 { s += "," } diff --git a/api/api_test.go b/api/api_test.go index a1c4a16f..92378a9d 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -217,7 +217,7 @@ func TestVK_RequestLimit(t *testing.T) { var wg sync.WaitGroup - for i := 0; i < 20; i++ { + for range 20 { wg.Add(1) go func() { diff --git a/api/oauth/oauth.go b/api/oauth/oauth.go index 3f2c8e30..6700003a 100644 --- a/api/oauth/oauth.go +++ b/api/oauth/oauth.go @@ -60,8 +60,8 @@ const ( // CheckScope ... func CheckScope(scope int, permissions ...int) bool { - for i := 0; i < len(permissions); i++ { - if scope&permissions[i] != permissions[i] { + for _, value := range permissions { + if scope&value != value { return false } } diff --git a/callback/callback_test.go b/callback/callback_test.go index 834bc7c2..8981ae5f 100644 --- a/callback/callback_test.go +++ b/callback/callback_test.go @@ -189,7 +189,6 @@ func TestCallback_HandleFunc(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() diff --git a/events/events.go b/events/events.go index 3ec3006b..d8044357 100644 --- a/events/events.go +++ b/events/events.go @@ -164,8 +164,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g if sliceFunc, ok := fl.special[e.Type]; ok { for _, f := range sliceFunc { - f := f - if fl.goroutine { go func() { f(ctx, e) }() } else { @@ -182,8 +180,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.messageNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -197,8 +193,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.messageReply { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -212,8 +206,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.messageEdit { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -227,8 +219,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.messageAllow { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -242,8 +232,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.messageDeny { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -257,8 +245,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.messageTypingState { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -272,8 +258,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.messageEvent { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -287,8 +271,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.photoNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -302,8 +284,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.photoCommentNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -317,8 +297,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.photoCommentEdit { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -332,8 +310,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.photoCommentRestore { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -347,8 +323,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.photoCommentDelete { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -362,8 +336,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.audioNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -377,8 +349,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.videoNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -392,8 +362,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.videoCommentNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -407,8 +375,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.videoCommentEdit { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -422,8 +388,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.videoCommentRestore { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -437,8 +401,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.videoCommentDelete { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -452,8 +414,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.wallPostNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -467,8 +427,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.wallRepost { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -482,8 +440,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.wallReplyNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -497,8 +453,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.wallReplyEdit { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -512,8 +466,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.wallReplyRestore { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -527,8 +479,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.wallReplyDelete { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -542,8 +492,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.boardPostNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -557,8 +505,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.boardPostEdit { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -572,8 +518,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.boardPostRestore { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -587,8 +531,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.boardPostDelete { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -602,8 +544,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.marketCommentNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -617,8 +557,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.marketCommentEdit { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -632,8 +570,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.marketCommentRestore { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -647,8 +583,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.marketCommentDelete { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -662,8 +596,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.marketOrderNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -677,8 +609,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.marketOrderEdit { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -692,8 +622,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.groupLeave { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -707,8 +635,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.groupJoin { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -722,8 +648,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.userBlock { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -737,8 +661,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.userUnblock { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -752,8 +674,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.pollVoteNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -767,8 +687,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.groupOfficersEdit { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -782,8 +700,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.groupChangeSettings { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -797,8 +713,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.groupChangePhoto { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -812,8 +726,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.vkpayTransaction { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -827,8 +739,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.leadFormsNew { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -842,8 +752,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.appPayload { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -857,8 +765,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.messageRead { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -872,8 +778,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.likeAdd { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -887,8 +791,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.likeRemove { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -902,8 +804,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.donutSubscriptionCreate { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -917,8 +817,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.donutSubscriptionProlonged { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -932,8 +830,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.donutSubscriptionExpired { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -947,8 +843,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.donutSubscriptionCancelled { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -962,8 +856,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.donutSubscriptionPriceChanged { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -977,8 +869,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.donutMoneyWithdraw { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { @@ -992,8 +882,6 @@ func (fl FuncList) Handler(ctx context.Context, e GroupEvent) error { //nolint:g } for _, f := range fl.donutMoneyWithdrawError { - f := f - if fl.goroutine { go func() { f(ctx, obj) }() } else { diff --git a/go.mod b/go.mod index ff0dddb3..56fc31ba 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/SevereCloud/vksdk/v3 -go 1.21 +go 1.22 require ( github.com/gorilla/schema v1.4.1 diff --git a/longpoll-bot/longpoll.go b/longpoll-bot/longpoll.go index 16a6ba9b..b9ef69fc 100644 --- a/longpoll-bot/longpoll.go +++ b/longpoll-bot/longpoll.go @@ -248,7 +248,7 @@ func (lp *LongPoll) run(ctx context.Context) error { return err } - ctx = context.WithValue(ctx, internal.LongPollTsKey, resp.Ts) + ctx := context.WithValue(ctx, internal.LongPollTsKey, resp.Ts) for _, event := range resp.Updates { err = lp.Handler(ctx, event) diff --git a/longpoll-bot/longpoll_test.go b/longpoll-bot/longpoll_test.go index 78456fc8..53d5d3ca 100644 --- a/longpoll-bot/longpoll_test.go +++ b/longpoll-bot/longpoll_test.go @@ -173,7 +173,6 @@ func TestLongPoll_checkResponse(t *testing.T) { //nolint: tparallel }, } for _, tt := range tests { //nolint: paralleltest - tt := tt t.Run(tt.name, func(t *testing.T) { if err := lp.checkResponse(tt.argResponse); (err != nil) != tt.wantErr { t.Errorf("LongPoll.checkResponse() error = %v, wantErr %v", err, tt.wantErr) @@ -254,7 +253,6 @@ func TestParseResponse(t *testing.T) { } for _, test := range tests { - test := test t.Run(test.name, func(t *testing.T) { t.Parallel() diff --git a/longpoll-user/longpoll.go b/longpoll-user/longpoll.go index b1d834a5..0142666a 100644 --- a/longpoll-user/longpoll.go +++ b/longpoll-user/longpoll.go @@ -210,8 +210,6 @@ func (lp LongPoll) handler(event []interface{}) error { key := int(event[0].(float64)) for _, f := range lp.funcList[key] { - f := f - if lp.goroutine { go func() { _ = f(event) }() } else { @@ -242,8 +240,6 @@ func (lp *LongPoll) Run() error { } for _, f := range lp.funcFullResponseList { - f := f - if lp.goroutine { go func() { f(resp) }() } else { diff --git a/longpoll-user/v3/extra.go b/longpoll-user/v3/extra.go index 4b1b8496..eb168588 100644 --- a/longpoll-user/v3/extra.go +++ b/longpoll-user/v3/extra.go @@ -194,7 +194,7 @@ func interfaceToIDSlice(slice interface{}) ([]int, error) { result := make([]int, reflectedSlice.Len()) - for i := 0; i < reflectedSlice.Len(); i++ { + for i := range reflectedSlice.Len() { v, ok := reflectedSlice.Index(i).Interface().(float64) if !ok { return nil, &failedCast{reflectedSlice.Index(i).Interface()} diff --git a/marusia/cards.go b/marusia/cards.go index 5e8e1e4e..592427f4 100644 --- a/marusia/cards.go +++ b/marusia/cards.go @@ -79,8 +79,8 @@ func NewItemsList(items ...CardItem) *Card { func NewImageList(imageIDs ...int) *Card { items := make([]CardItem, len(imageIDs)) - for i := 0; i < len(imageIDs); i++ { - items[i].ImageID = imageIDs[i] + for i, value := range imageIDs { + items[i].ImageID = value } return NewItemsList(items...)