mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
use slices package and remove some helpers (#17342)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user