forked from electricdusk/rushlink
Use sql database instead of bolt
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user