added prefix scan and fixed logout issue
This commit is contained in:
parent
4812a60367
commit
8143e484cd
12 changed files with 99 additions and 77 deletions
|
|
@ -119,6 +119,15 @@ func (bs *BoltStore) ForEach(f func(string, []byte) error) error {
|
|||
})
|
||||
}
|
||||
|
||||
func (bs *BoltStore) ForEachPrefix(prefix string, f func(string, []byte) error) error {
|
||||
return bs.ForEach(func(k string, v []byte) error {
|
||||
if trim, ok := hasTrimPrefix(k, prefix); ok {
|
||||
return f(trim, v)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (bs *BoltStore) Delete(key string) error {
|
||||
return bs.db.Update(func(tx *bolt.Tx) error {
|
||||
return tx.Bucket([]byte(defaultBoltBucket)).Delete([]byte(key))
|
||||
|
|
|
|||
11
pkg/store/helper.go
Normal file
11
pkg/store/helper.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2019 Marius Schellenberger
|
||||
|
||||
package store
|
||||
|
||||
// Parts taken from strings.TrimPrefix
|
||||
func hasTrimPrefix(s, prefix string) (string, bool) {
|
||||
if len(s) >= len(prefix) && s[0:len(prefix)] == prefix {
|
||||
return s[len(prefix):], true
|
||||
}
|
||||
return s, false
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ type Store interface {
|
|||
Get(string, interface{}) error
|
||||
Set(string, interface{}) error
|
||||
ForEach(func(string, []byte) error) error
|
||||
ForEachPrefix(string, func(string, []byte) error) error
|
||||
Delete(string) error
|
||||
Close() error
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue