Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Go 1.21 #980

Merged
merged 14 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
go_versions: [ '1.20', '1.21', '1.22' ]
go_versions: [ '1.21', '1.22' ]
fail-fast: false
steps:
- uses: actions/checkout@v4
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ This document outlines major changes between releases.

### Changed
- Single `rpc_endpoint` config option replaced with multiple endpoints `fschain.endpoints` option (#968)
- Go 1.21+ is required to build now (#811)

### Updated
- github.com/nspcc-dev/neo-go dependency from v0.106.2 to v0.106.3 (#811)
- github.com/urfave/cli/v2 dependency from v2.3.0 to v2.27.2 (#811)
- github.com/nspcc-dev/neofs-contract dependency from v0.19.2-0.20240610103236-d50c8e0c9396 to v0.20.0 (#811)
- golang.org/x/crypto dependency from v0.21.0 to v0.26.0 (#811)
- github.com/nspcc-dev/tzhash dependency from v1.8.0 to v1.8.1 (#811)
- github.com/prometheus/client_golang dependency from v1.19.0 to v1.20.0 (#811)
- google.golang.org/protobuf dependency from v1.33.0 to v1.34.2 (#811)
- github.com/panjf2000/ants/v2 dependency from v2.5.0 to v2.10.0 (#811)
- github.com/aws/aws-sdk-go dependency from v1.50.27 to v1.55.5 (#811)
- github.com/spf13/viper dependency from v1.18.2 to v1.19.0 (#811)
- github.com/nats-io/nats.go dependency from v1.31.0 to v1.34.0 (#811)
- google.golang.org/grpc dependency from v1.62.0 to v1.62.1 (#811)
- github.com/minio/sio dependency from v0.3.0 to v0.4.0 (#811)

### Updating from 0.30.1

Expand Down
6 changes: 3 additions & 3 deletions api/auth/signer/v4/v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import (
"io"
"net/http"
"net/url"
"sort"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -340,7 +340,7 @@ func (v4 Signer) signWithBody(r *http.Request, body io.ReadSeeker, service, regi
}

for key := range ctx.Query {
sort.Strings(ctx.Query[key])
slices.Sort(ctx.Query[key])
}

if ctx.isRequestSigned() {
Expand Down Expand Up @@ -637,7 +637,7 @@ func (ctx *signingCtx) buildCanonicalHeaders(r rule, header http.Header) {
headers = append(headers, lowerCaseKey)
ctx.SignedHeaderVals[lowerCaseKey] = v
}
sort.Strings(headers)
slices.Sort(headers)

ctx.signedHeaders = strings.Join(headers, ";")

Expand Down
22 changes: 7 additions & 15 deletions api/handler/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package handler

import (
"bytes"
"cmp"
"context"
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"net/http"
"sort"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -674,8 +675,8 @@ func formReverseOrderResources(resourceMap map[string]orderedAstResource) []*ast
for _, resource := range resourceMap {
orderedResources = append(orderedResources, resource)
}
sort.Slice(orderedResources, func(i, j int) bool {
return orderedResources[i].Index >= orderedResources[j].Index // reverse order
slices.SortFunc(orderedResources, func(a, b orderedAstResource) int {
return cmp.Compare(b.Index, a.Index) // reverse order
})

result := make([]*astResource, len(orderedResources))
Expand Down Expand Up @@ -801,7 +802,7 @@ func mergeAst(parent, child *ast) (*ast, bool) {
func handleAddOperations(parentResource *astResource, astOp, existedOp *astOperation) bool {
var needToAdd []user.ID
for _, user := range astOp.Users {
if !containsUser(existedOp.Users, user) {
if !slices.Contains(existedOp.Users, user) {
needToAdd = append(needToAdd, user)
}
}
Expand All @@ -815,7 +816,7 @@ func handleAddOperations(parentResource *astResource, astOp, existedOp *astOpera
func handleRemoveOperations(parentResource *astResource, astOp, existedOp *astOperation) bool {
var needToRemove []user.ID
for _, user := range astOp.Users {
if containsUser(existedOp.Users, user) {
if slices.Contains(existedOp.Users, user) {
needToRemove = append(needToRemove, user)
}
}
Expand All @@ -827,15 +828,6 @@ func handleRemoveOperations(parentResource *astResource, astOp, existedOp *astOp
return false
}

func containsUser(list []user.ID, element user.ID) bool {
for _, str := range list {
if str == element {
return true
}
}
return false
}

func getAstOps(resource *astResource, childOp *astOperation) []*astOperation {
var res []*astOperation
for _, astOp := range resource.Operations {
Expand Down Expand Up @@ -869,7 +861,7 @@ func removeUsers(resource *astResource, astOperation *astOperation, users []user
if !astOp.IsGroupGrantee() && astOp.Op == astOperation.Op && astOp.Action == astOperation.Action {
filteredUsers := astOp.Users[:0] // new slice without allocation
for _, user := range astOp.Users {
if !containsUser(users, user) {
if !slices.Contains(users, user) {
filteredUsers = append(filteredUsers, user)
}
}
Expand Down
8 changes: 5 additions & 3 deletions api/handler/tagging.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package handler

import (
"cmp"
"encoding/xml"
"io"
"net/http"
"sort"
"slices"
"strings"
"unicode"

Expand Down Expand Up @@ -227,8 +228,9 @@ func encodeTagging(tagSet map[string]string) *Tagging {
for k, v := range tagSet {
tagging.TagSet = append(tagging.TagSet, Tag{Key: k, Value: v})
}
sort.Slice(tagging.TagSet, func(i, j int) bool {
return tagging.TagSet[i].Key < tagging.TagSet[j].Key

slices.SortFunc(tagging.TagSet, func(a, b Tag) int {
return cmp.Compare(a.Key, b.Key)
})

return tagging
Expand Down
16 changes: 8 additions & 8 deletions api/layer/multipart_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package layer

import (
"bytes"
"cmp"
"context"
"crypto/sha256"
"encoding"
Expand All @@ -10,7 +11,7 @@ import (
"fmt"
"hash"
"io"
"sort"
"slices"
"strconv"
"strings"
"time"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/version"
"github.com/nspcc-dev/tzhash/tz"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

const (
Expand Down Expand Up @@ -918,11 +918,11 @@ func (n *layer) ListMultipartUploads(ctx context.Context, p *ListMultipartUpload
}
}

sort.Slice(uploads, func(i, j int) bool {
if uploads[i].Key == uploads[j].Key {
return uploads[i].UploadID < uploads[j].UploadID
slices.SortFunc(uploads, func(a, b *UploadInfo) int {
if compare := cmp.Compare(a.Key, b.Key); compare != 0 {
return compare
}
return uploads[i].Key < uploads[j].Key
return cmp.Compare(a.UploadID, b.UploadID)
})

if p.KeyMarker != "" {
Expand Down Expand Up @@ -999,8 +999,8 @@ func (n *layer) ListParts(ctx context.Context, p *ListPartsParams) (*ListPartsIn
})
}

sort.Slice(parts, func(i, j int) bool {
return parts[i].PartNumber < parts[j].PartNumber
slices.SortFunc(parts, func(a, b *Part) int {
return cmp.Compare(a.PartNumber, b.PartNumber)
})

if p.PartNumberMarker != 0 {
Expand Down
12 changes: 7 additions & 5 deletions api/layer/multipart_upload_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package layer

import (
"sort"
"cmp"
"slices"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -27,11 +28,12 @@ func TestTrimAfterUploadIDAndKey(t *testing.T) {
{},
}

sort.Slice(uploads, func(i, j int) bool {
if uploads[i].Key == uploads[j].Key {
return uploads[i].UploadID < uploads[j].UploadID
slices.SortFunc(uploads, func(a, b *UploadInfo) int {
if compare := cmp.Compare(a.Key, b.Key); compare != 0 {
return compare
}
return uploads[i].Key < uploads[j].Key

return cmp.Compare(a.UploadID, b.UploadID)
})

length := len(uploads)
Expand Down
11 changes: 6 additions & 5 deletions api/layer/object.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package layer

import (
"cmp"
"context"
"crypto/sha256"
"encoding/hex"
Expand All @@ -10,7 +11,7 @@ import (
"io"
"mime"
"path/filepath"
"sort"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -573,8 +574,8 @@ func (n *layer) getLatestObjectsVersions(ctx context.Context, p allObjectParams)
return nil, nil, nil
}

sort.Slice(nodeVersions, func(i, j int) bool {
return nodeVersions[i].FilePath < nodeVersions[j].FilePath
slices.SortFunc(nodeVersions, func(a, b *data.NodeVersion) int {
return cmp.Compare(a.FilePath, b.FilePath)
})

poolCtx, cancel := context.WithCancel(ctx)
Expand All @@ -590,8 +591,8 @@ func (n *layer) getLatestObjectsVersions(ctx context.Context, p allObjectParams)
objects = append(objects, obj)
}

sort.Slice(objects, func(i, j int) bool {
return objects[i].Name < objects[j].Name
slices.SortFunc(objects, func(a, b *data.ObjectInfo) int {
return cmp.Compare(a.Name, b.Name)
})

if len(objects) > p.MaxKeys {
Expand Down
16 changes: 8 additions & 8 deletions api/layer/tree_mock.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package layer

import (
"cmp"
"context"
"fmt"
"sort"
"slices"
"strings"

"github.com/nspcc-dev/neofs-s3-gw/api/data"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"golang.org/x/exp/slices"
)

type TreeServiceMock struct {
Expand Down Expand Up @@ -146,8 +146,8 @@ func (t *TreeServiceMock) GetLatestVersion(_ context.Context, bktInfo *data.Buck
return nil, ErrNodeNotFound
}

sort.Slice(versions, func(i, j int) bool {
return versions[i].ID < versions[j].ID
slices.SortFunc(versions, func(a, b *data.NodeVersion) int {
return cmp.Compare(a.ID, b.ID)
})

if len(versions) != 0 {
Expand All @@ -170,8 +170,8 @@ func (t *TreeServiceMock) GetLatestVersionsByPrefix(_ context.Context, bktInfo *
continue
}

sort.Slice(versions, func(i, j int) bool {
return versions[i].ID < versions[j].ID
slices.SortFunc(versions, func(a, b *data.NodeVersion) int {
return cmp.Compare(a.ID, b.ID)
})

if len(versions) != 0 {
Expand Down Expand Up @@ -217,8 +217,8 @@ func (t *TreeServiceMock) AddVersion(_ context.Context, bktInfo *data.BucketInfo
return newVersion.ID, nil
}

sort.Slice(versions, func(i, j int) bool {
return versions[i].ID < versions[j].ID
slices.SortFunc(versions, func(a, b *data.NodeVersion) int {
return cmp.Compare(a.ID, b.ID)
})

if len(versions) != 0 {
Expand Down
9 changes: 5 additions & 4 deletions api/layer/versioning.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package layer

import (
"cmp"
"context"
"sort"
"slices"

"github.com/nspcc-dev/neofs-s3-gw/api/data"
)
Expand All @@ -22,12 +23,12 @@ func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsPar
for k := range versions {
sortedNames = append(sortedNames, k)
}
sort.Strings(sortedNames)
slices.Sort(sortedNames)

for _, name := range sortedNames {
sortedVersions := versions[name]
sort.Slice(sortedVersions, func(i, j int) bool {
return sortedVersions[j].NodeVersion.Timestamp < sortedVersions[i].NodeVersion.Timestamp // sort in reverse order
slices.SortFunc(sortedVersions, func(a, b *data.ExtendedObjectInfo) int {
return cmp.Compare(b.NodeVersion.Timestamp, a.NodeVersion.Timestamp) // sort in reverse order
})

for i, version := range sortedVersions {
Expand Down
4 changes: 2 additions & 2 deletions cmd/s3-gw/app_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"
"runtime"
"sort"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -287,7 +287,7 @@ func newSettings() *viper.Viper {
fmt.Println("Default environments:")
fmt.Println()
keys := v.AllKeys()
sort.Strings(keys)
slices.Sort(keys)

for i := range keys {
if _, ok := ignore[keys[i]]; ok {
Expand Down
Loading
Loading