store/memory: small fixups for flow usage

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-07-15 11:59:35 +03:00
parent 42800fa247
commit 1e43122660

View File

@ -74,13 +74,17 @@ func (m *memoryStore) list(prefix string, limit, offset uint) []string {
i := 0 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+"/") if prefix == "" {
allKeys[i] = strings.TrimPrefix(k, "/")
} else {
allKeys[i] = strings.TrimPrefix(k, prefix)
}
allKeys[i] = strings.TrimPrefix(allKeys[i], "/")
i++ 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(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] })
sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] }) sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] })
@ -137,6 +141,9 @@ func (m *memoryStore) Write(ctx context.Context, key string, val interface{}, op
if options.Namespace == "" { if options.Namespace == "" {
options.Namespace = m.opts.Namespace options.Namespace = m.opts.Namespace
} }
if options.TTL == 0 {
options.TTL = cache.NoExpiration
}
key = m.key(options.Namespace, key) key = m.key(options.Namespace, key)