cli and ls s3

This commit is contained in:
Bel LaPointe
2020-02-13 07:12:40 -07:00
parent d39c226d13
commit be25dee55d
3 changed files with 35 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"io/ioutil"
"net/url"
"sort"
"strings"
minio "github.com/minio/minio-go"
@@ -29,7 +30,8 @@ func (m *Minio) List(ns []string, limits ...string) ([]string, error) {
done := make(chan struct{})
defer close(done)
keys := []string{}
for resp := range m.db.ListObjects(namespace, "", true, done) {
prefix := commonSubstr(limits[:2])
for resp := range m.db.ListObjects(namespace, prefix, true, done) {
if resp.Err != nil {
return keys, resp.Err
}
@@ -81,3 +83,26 @@ func (m *Minio) Close() error {
func isNotExistErr(err error) bool {
return err != nil && strings.Contains(err.Error(), "does not exist")
}
func commonSubstr(items []string) string {
if len(items) == 0 {
return ""
} else if len(items) == 1 {
return items[0]
}
sort.Strings(items)
min := items[0]
max := items[len(items)-1]
if len(min) == 0 || len(max) == 0 {
return ""
}
if min[0] != max[0] {
return ""
}
for i := 1; i < len(min) && i < len(max); i++ {
if min[i] != max[i] {
return min[:i-1]
}
}
return min
}