Use sql database instead of bolt

This commit is contained in:
Daan Sprenkels
2020-10-25 17:33:51 +01:00
parent f36fa30eff
commit 0048004252
17 changed files with 1101 additions and 105 deletions

View File

@@ -322,3 +322,24 @@ func GenerateDeleteToken() (string, error) {
}
return hex.EncodeToString(deleteToken[:]), nil
}
// AllPastes tries to retrieve all the Paste objects from the database.
func AllPastes(tx *bolt.Tx) ([]Paste, error) {
bucket := tx.Bucket([]byte(BucketPastes))
if bucket == nil {
return nil, errors.Errorf("bucket %v does not exist", BucketPastes)
}
var ps []Paste
err := bucket.ForEach(func(_, storedBytes []byte) error {
p, err := decodePaste(storedBytes)
if err != nil {
return err
}
ps = append(ps, *p)
return nil
})
if err != nil {
return nil, err
}
return ps, nil
}