mirror of
https://github.com/go-micro/go-micro.git
synced 2025-06-12 22:07:47 +02:00
fix: prevent returning empty strings for list (#2553)
This commit is contained in:
@ -121,29 +121,27 @@ func (m *memoryStore) delete(prefix, key string) {
|
|||||||
|
|
||||||
func (m *memoryStore) list(prefix string, limit, offset uint) []string {
|
func (m *memoryStore) list(prefix string, limit, offset uint) []string {
|
||||||
allItems := m.store.Items()
|
allItems := m.store.Items()
|
||||||
allKeys := make([]string, len(allItems))
|
foundKeys := make([]string, 0, len(allItems))
|
||||||
i := 0
|
|
||||||
|
|
||||||
for k := range allItems {
|
for k := range allItems {
|
||||||
if !strings.HasPrefix(k, prefix+"/") {
|
if !strings.HasPrefix(k, prefix+"/") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
allKeys[i] = strings.TrimPrefix(k, prefix+"/")
|
foundKeys = append(foundKeys, strings.TrimPrefix(k, prefix+"/"))
|
||||||
i++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if limit != 0 || offset != 0 {
|
if limit != 0 || offset != 0 {
|
||||||
sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] })
|
sort.Slice(foundKeys, func(i, j int) bool { return foundKeys[i] < foundKeys[j] })
|
||||||
min := func(i, j uint) uint {
|
min := func(i, j uint) uint {
|
||||||
if i < j {
|
if i < j {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
return j
|
return j
|
||||||
}
|
}
|
||||||
return allKeys[offset:min(limit, uint(len(allKeys)))]
|
return foundKeys[offset:min(limit, uint(len(foundKeys)))]
|
||||||
}
|
}
|
||||||
|
|
||||||
return allKeys
|
return foundKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *memoryStore) Close() error {
|
func (m *memoryStore) Close() error {
|
||||||
|
Reference in New Issue
Block a user