From eb9a4a83ac0830034deea4a8278ac10a837200ca Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 1 Mar 2015 11:18:34 -0800 Subject: [PATCH] Move AppendUstr(), AppendUint() into helpers --- pkg/storage/fs/fs.go | 14 +++----------- pkg/utils/helpers/common.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/pkg/storage/fs/fs.go b/pkg/storage/fs/fs.go index bb839a664..f8ce1a2c5 100644 --- a/pkg/storage/fs/fs.go +++ b/pkg/storage/fs/fs.go @@ -29,6 +29,7 @@ import ( "sync" mstorage "github.com/minio-io/minio/pkg/storage" + "github.com/minio-io/minio/pkg/utils/helpers" "github.com/minio-io/minio/pkg/utils/policy" ) @@ -328,15 +329,6 @@ func delimiter(path, delimiter string) string { return delimited } -func appendU(slice []string, i string) []string { - for _, ele := range slice { - if ele == i { - return slice - } - } - return append(slice, i) -} - type ByObjectKey []mstorage.ObjectMetadata func (b ByObjectKey) Len() int { return len(b) } @@ -387,7 +379,7 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso } metadataList = append(metadataList, metadata) case delimited != "": - resources.CommonPrefixes = appendU(resources.CommonPrefixes, delimited) + resources.CommonPrefixes = helpers.AppendUstr(resources.CommonPrefixes, delimited) } case resources.Delimiter != "" && strings.HasPrefix(name, resources.Prefix): delimited := delimiter(name, resources.Delimiter) @@ -402,7 +394,7 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso } metadataList = append(metadataList, metadata) case delimited != "": - resources.CommonPrefixes = appendU(resources.CommonPrefixes, delimited) + resources.CommonPrefixes = helpers.AppendUstr(resources.CommonPrefixes, delimited) } case strings.HasPrefix(name, resources.Prefix): metadata := mstorage.ObjectMetadata{ diff --git a/pkg/utils/helpers/common.go b/pkg/utils/helpers/common.go index 5de35ff0f..058ef7617 100644 --- a/pkg/utils/helpers/common.go +++ b/pkg/utils/helpers/common.go @@ -52,3 +52,21 @@ func Assert(err error) { func FirstUpper(str string) string { return strings.ToUpper(str[0:1]) + str[1:] } + +func AppendUint(slice []int, i int) []int { + for _, ele := range slice { + if ele == i { + return slice + } + } + return append(slice, i) +} + +func AppendUstr(slice []string, i string) []string { + for _, ele := range slice { + if ele == i { + return slice + } + } + return append(slice, i) +}