Skip to content

Commit

Permalink
Move AppendUstr(), AppendUint() into helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshavardhana committed Mar 1, 2015
1 parent 9fb67c4 commit eb9a4a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
14 changes: 3 additions & 11 deletions pkg/storage/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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)
Expand All @@ -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{
Expand Down
18 changes: 18 additions & 0 deletions pkg/utils/helpers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit eb9a4a8

Please sign in to comment.