added expire check code + db iterator func

This commit is contained in:
2023-03-01 16:28:53 +01:00
parent 84bef91657
commit d4f2d6eb76
5 changed files with 128 additions and 4 deletions

View File

@@ -124,3 +124,23 @@ func (db *Db) Delete(id string) error {
return err
}
func (db *Db) Iterate(iterator func(id string, upload Upload)) error {
var upload Upload
err := db.bolt.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(Bucket))
err := bucket.ForEach(func(id, j []byte) error {
if err := json.Unmarshal(j, &upload); err != nil {
return fmt.Errorf("unable to unmarshal json: %s", err)
}
iterator(string(id), upload)
return nil
})
return err // might be nil as well
})
return err
}