blob: 0aeec155b778c6de8bfaba13b19a92f2e6b35558 [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
Jon Perritt0ce24ad2014-10-20 21:59:45 -05007 "github.com/rackspace/gophercloud"
8)
9
10// DeleteOptsBuilder allows extensions to add additional parameters to the
11// Delete request.
12type DeleteOptsBuilder interface {
13 ToBulkDeleteBody() (string, error)
14}
15
16// DeleteOpts is a structure that holds parameters for deleting an object.
17type DeleteOpts []string
18
19// ToBulkDeleteBody formats a DeleteOpts into a request body.
20func (opts DeleteOpts) ToBulkDeleteBody() (string, error) {
21 return url.QueryEscape(strings.Join(opts, "\n")), nil
22}
23
24// Delete will delete objects or containers in bulk.
25func Delete(c *gophercloud.ServiceClient, opts DeleteOptsBuilder) DeleteResult {
26 var res DeleteResult
27
28 if opts == nil {
29 return res
30 }
31
32 reqString, err := opts.ToBulkDeleteBody()
33 if err != nil {
34 res.Err = err
35 return res
36 }
37
Jon Perritt260e0882014-10-20 23:31:23 -050038 reqBody := strings.NewReader(reqString)
Jon Perritt0ce24ad2014-10-20 21:59:45 -050039
Ash Wilson2199f102015-02-12 16:16:09 -050040 resp, err := c.Request("DELETE", deleteURL(c), gophercloud.RequestOpts{
41 MoreHeaders: map[string]string{"Content-Type": "text/plain"},
42 OkCodes: []int{200},
43 JSONBody: reqBody,
44 JSONResponse: &res.Body,
Jon Perritt0ce24ad2014-10-20 21:59:45 -050045 })
Jon Perritta2c88b22015-05-18 11:23:30 -060046 if resp != nil {
47 res.Header = resp.Header
48 }
Jon Perritt0ce24ad2014-10-20 21:59:45 -050049 res.Err = err
50 return res
51}