diff --git a/client/serverstorage.go b/client/serverstorage.go index f84f85b..aa236c6 100644 --- a/client/serverstorage.go +++ b/client/serverstorage.go @@ -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