diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-04-29 23:01:51 -0500 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-04-29 23:01:51 -0500 |
commit | 8a1d091a0c6d55dbd6c713b2240bee8550541e7b (patch) | |
tree | 8ebe1e3f0780f66530b723ce9b48f69ae664d764 /system/db | |
parent | 3c8c848606b996e2c7a06331401e622f888b84c5 (diff) |
add delete procedure and implementation for uploads
Diffstat (limited to 'system/db')
-rw-r--r-- | system/db/upload.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/system/db/upload.go b/system/db/upload.go index 956b7f9..beeee2d 100644 --- a/system/db/upload.go +++ b/system/db/upload.go @@ -201,6 +201,28 @@ func UploadAll() [][]byte { return uploads } +// DeleteUpload removes the value for an upload at its key id, based on the +// target provided i.e. __uploads:{id} +func DeleteUpload(target string) error { + parts := strings.Split(target, ":") + if len(parts) < 2 { + return fmt.Errorf("Error deleting upload, invalid target %s", target) + } + id, err := key(parts[1]) + if err != nil { + return err + } + + return store.Update(func(tx *bolt.Tx) error { + b := tx.Bucket([]byte(parts[0])) + if b == nil { + return bolt.ErrBucketNotFound + } + + return b.Delete(id) + }) +} + func key(sid string) ([]byte, error) { id, err := strconv.Atoi(sid) if err != nil { |