add LoadAllServerCards from badger
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
978b6fdfd1
commit
b87c0bff3e
@ -126,6 +126,39 @@ func (ss *ServerStorage) LoadAllServers() ([]*Server, error) {
|
||||
return scs, err
|
||||
}
|
||||
|
||||
// LoadAllServers function loads all ServersCards from a badger database
|
||||
func (ss *ServerStorage) LoadAllServerCards() ([]*meowlib.ServerCard, error) {
|
||||
var scs []*meowlib.ServerCard
|
||||
err := ss.open()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer ss.close()
|
||||
err = ss.db.View(func(txn *badger.Txn) error {
|
||||
opts := badger.DefaultIteratorOptions
|
||||
opts.PrefetchSize = 10
|
||||
it := txn.NewIterator(opts)
|
||||
defer it.Close()
|
||||
for it.Rewind(); it.Valid(); it.Next() {
|
||||
item := it.Item()
|
||||
var sc Server
|
||||
err := item.Value(func(val []byte) error {
|
||||
jsonsrv, err := meowlib.SymDecrypt(GetConfig().memoryPassword, val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return json.Unmarshal(jsonsrv, &sc)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
scs = append(scs, sc.GetServerCard())
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return scs, err
|
||||
}
|
||||
|
||||
// LoadServersFromUids function loads Servers with id in []Uid parameter from a badger database
|
||||
func (ss *ServerStorage) LoadServersFromUids(uids []string) ([]*Server, error) {
|
||||
var scs []*Server
|
||||
|
Loading…
Reference in New Issue
Block a user