blob: 7a0886927c57e0d65048285209c16cf063ce4032 [file] [log] [blame]
Jon Perritt0ce24ad2014-10-20 21:59:45 -05001package bulk
2
3import (
Jon Perritt0ce24ad2014-10-20 21:59:45 -05004 "net/url"
Jon Perritt0ce24ad2014-10-20 21:59:45 -05005 "strings"
6
7 "github.com/racker/perigee"
8 "github.com/rackspace/gophercloud"
9)
10
11// DeleteOptsBuilder allows extensions to add additional parameters to the
12// Delete request.
13type DeleteOptsBuilder interface {
14 ToBulkDeleteBody() (string, error)
15}
16
17// DeleteOpts is a structure that holds parameters for deleting an object.
18type DeleteOpts []string
19
20// ToBulkDeleteBody formats a DeleteOpts into a request body.
21func (opts DeleteOpts) ToBulkDeleteBody() (string, error) {
22 return url.QueryEscape(strings.Join(opts, "\n")), nil
23}
24
25// Delete will delete objects or containers in bulk.
26func Delete(c *gophercloud.ServiceClient, opts DeleteOptsBuilder) DeleteResult {
27 var res DeleteResult
28
29 if opts == nil {
30 return res
31 }
32
33 reqString, err := opts.ToBulkDeleteBody()
34 if err != nil {
35 res.Err = err
36 return res
37 }
38
Jon Perritt260e0882014-10-20 23:31:23 -050039 reqBody := strings.NewReader(reqString)
Jon Perritt0ce24ad2014-10-20 21:59:45 -050040
41 resp, err := perigee.Request("DELETE", deleteURL(c), perigee.Options{
Jon Perritt260e0882014-10-20 23:31:23 -050042 ContentType: "text/plain",
Jon Perritt0ce24ad2014-10-20 21:59:45 -050043 MoreHeaders: c.Provider.AuthenticatedHeaders(),
44 OkCodes: []int{200},
45 ReqBody: reqBody,
46 Results: &res.Body,
47 })
48 res.Header = resp.HttpResponse.Header
49 res.Err = err
50 return res
51}