mirror of
https://github.com/minio/minio.git
synced 2024-12-23 21:55:53 -05:00
use slices package and remove some helpers (#17342)
This commit is contained in:
parent
5a21b1f353
commit
d1448adbda
33
CREDITS
33
CREDITS
@ -28435,6 +28435,39 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
================================================================
|
||||
|
||||
golang.org/x/exp
|
||||
https://golang.org/x/exp
|
||||
----------------------------------------------------------------
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
================================================================
|
||||
|
||||
golang.org/x/mod
|
||||
https://golang.org/x/mod
|
||||
----------------------------------------------------------------
|
||||
|
@ -49,6 +49,7 @@ import (
|
||||
"github.com/minio/minio/internal/logger"
|
||||
"github.com/minio/pkg/trie"
|
||||
"github.com/minio/pkg/wildcard"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -377,7 +378,7 @@ func removeStandardStorageClass(metadata map[string]string) map[string]string {
|
||||
func cleanMetadataKeys(metadata map[string]string, keyNames ...string) map[string]string {
|
||||
newMeta := make(map[string]string, len(metadata))
|
||||
for k, v := range metadata {
|
||||
if contains(keyNames, k) {
|
||||
if slices.Contains(keyNames, k) {
|
||||
continue
|
||||
}
|
||||
newMeta[k] = v
|
||||
|
@ -50,6 +50,7 @@ import (
|
||||
"github.com/minio/minio/internal/logger"
|
||||
"github.com/minio/pkg/certs"
|
||||
"github.com/minio/pkg/env"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
// ServerFlags - server command specific flags
|
||||
@ -792,7 +793,7 @@ func serverMain(ctx *cli.Context) {
|
||||
}
|
||||
for _, v := range os.Environ() {
|
||||
// Do not print sensitive creds in debug.
|
||||
if contains(ks, strings.Split(v, "=")[0]) {
|
||||
if slices.Contains(ks, strings.Split(v, "=")[0]) {
|
||||
continue
|
||||
}
|
||||
logger.Info(v)
|
||||
|
@ -31,6 +31,7 @@ import (
|
||||
xhttp "github.com/minio/minio/internal/http"
|
||||
"github.com/minio/minio/internal/logger"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
// http Header "x-amz-content-sha256" == "UNSIGNED-PAYLOAD" indicates that the
|
||||
@ -199,7 +200,7 @@ func extractSignedHeaders(signedHeaders []string, r *http.Request) (http.Header,
|
||||
reqQueries := r.Form
|
||||
// find whether "host" is part of list of signed headers.
|
||||
// if not return ErrUnsignedHeaders. "host" is mandatory.
|
||||
if !contains(signedHeaders, "host") {
|
||||
if !slices.Contains(signedHeaders, "host") {
|
||||
return nil, ErrUnsignedHeaders
|
||||
}
|
||||
extractedSignedHeaders := make(http.Header)
|
||||
|
13
cmd/utils.go
13
cmd/utils.go
@ -32,7 +32,6 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"runtime/trace"
|
||||
@ -278,18 +277,6 @@ func isMaxPartID(partID int) bool {
|
||||
return partID > globalMaxPartID
|
||||
}
|
||||
|
||||
func contains(slice interface{}, elem interface{}) bool {
|
||||
v := reflect.ValueOf(slice)
|
||||
if v.Kind() == reflect.Slice {
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
if v.Index(i).Interface() == elem {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// profilerWrapper is created becauses pkg/profiler doesn't
|
||||
// provide any API to calculate the profiler file path in the
|
||||
// disk since the name of this latter is randomly generated.
|
||||
|
@ -288,40 +288,6 @@ func TestToS3ETag(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test contains
|
||||
func TestContains(t *testing.T) {
|
||||
testErr := errors.New("test err")
|
||||
|
||||
testCases := []struct {
|
||||
slice interface{}
|
||||
elem interface{}
|
||||
found bool
|
||||
}{
|
||||
{nil, nil, false},
|
||||
{"1", "1", false},
|
||||
{nil, "1", false},
|
||||
{[]string{"1"}, nil, false},
|
||||
{[]string{}, "1", false},
|
||||
{[]string{"1"}, "1", true},
|
||||
{[]string{"2"}, "1", false},
|
||||
{[]string{"1", "2"}, "1", true},
|
||||
{[]string{"2", "1"}, "1", true},
|
||||
{[]string{"2", "1", "3"}, "1", true},
|
||||
{[]int{1, 2, 3}, "1", false},
|
||||
{[]int{1, 2, 3}, 2, true},
|
||||
{[]int{1, 2, 3, 4, 5, 6}, 7, false},
|
||||
{[]error{errors.New("new err")}, testErr, false},
|
||||
{[]error{errors.New("new err"), testErr}, testErr, true},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
found := contains(testCase.slice, testCase.elem)
|
||||
if found != testCase.found {
|
||||
t.Fatalf("Test %v: expected: %v, got: %v", i+1, testCase.found, found)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test ceilFrac
|
||||
func TestCeilFrac(t *testing.T) {
|
||||
cases := []struct {
|
||||
|
1
go.mod
1
go.mod
@ -88,6 +88,7 @@ require (
|
||||
go.uber.org/zap v1.24.0
|
||||
goftp.io/server/v2 v2.0.0
|
||||
golang.org/x/crypto v0.9.0
|
||||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
|
||||
golang.org/x/oauth2 v0.8.0
|
||||
golang.org/x/sys v0.8.0
|
||||
golang.org/x/time v0.3.0
|
||||
|
2
go.sum
2
go.sum
@ -1179,6 +1179,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
|
||||
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
||||
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
|
||||
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
|
||||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
|
||||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
|
Loading…
Reference in New Issue
Block a user