github.com/gophercloud/gophercloud@v1.11.0/openstack/objectstorage/v1/accounts/requests.go (about) 1 package accounts 2 3 import "github.com/gophercloud/gophercloud" 4 5 // GetOptsBuilder allows extensions to add additional headers to the Get 6 // request. 7 type GetOptsBuilder interface { 8 ToAccountGetMap() (map[string]string, error) 9 } 10 11 // GetOpts is a structure that contains parameters for getting an account's 12 // metadata. 13 type GetOpts struct { 14 Newest bool `h:"X-Newest"` 15 } 16 17 // ToAccountGetMap formats a GetOpts into a map[string]string of headers. 18 func (opts GetOpts) ToAccountGetMap() (map[string]string, error) { 19 return gophercloud.BuildHeaders(opts) 20 } 21 22 // Get is a function that retrieves an account's metadata. To extract just the 23 // custom metadata, call the ExtractMetadata method on the GetResult. To extract 24 // all the headers that are returned (including the metadata), call the 25 // Extract method on the GetResult. 26 func Get(c *gophercloud.ServiceClient, opts GetOptsBuilder) (r GetResult) { 27 h := make(map[string]string) 28 if opts != nil { 29 headers, err := opts.ToAccountGetMap() 30 if err != nil { 31 r.Err = err 32 return 33 } 34 for k, v := range headers { 35 h[k] = v 36 } 37 } 38 resp, err := c.Head(getURL(c), &gophercloud.RequestOpts{ 39 MoreHeaders: h, 40 OkCodes: []int{204}, 41 }) 42 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 43 return 44 } 45 46 // UpdateOptsBuilder allows extensions to add additional headers to the Update 47 // request. 48 type UpdateOptsBuilder interface { 49 ToAccountUpdateMap() (map[string]string, error) 50 } 51 52 // UpdateOpts is a structure that contains parameters for updating, creating, or 53 // deleting an account's metadata. 54 type UpdateOpts struct { 55 Metadata map[string]string 56 RemoveMetadata []string 57 ContentType *string `h:"Content-Type"` 58 DetectContentType *bool `h:"X-Detect-Content-Type"` 59 TempURLKey string `h:"X-Account-Meta-Temp-URL-Key"` 60 TempURLKey2 string `h:"X-Account-Meta-Temp-URL-Key-2"` 61 } 62 63 // ToAccountUpdateMap formats an UpdateOpts into a map[string]string of headers. 64 func (opts UpdateOpts) ToAccountUpdateMap() (map[string]string, error) { 65 headers, err := gophercloud.BuildHeaders(opts) 66 if err != nil { 67 return nil, err 68 } 69 70 for k, v := range opts.Metadata { 71 headers["X-Account-Meta-"+k] = v 72 } 73 74 for _, k := range opts.RemoveMetadata { 75 headers["X-Remove-Account-Meta-"+k] = "remove" 76 } 77 78 return headers, err 79 } 80 81 // Update is a function that creates, updates, or deletes an account's metadata. 82 // To extract the headers returned, call the Extract method on the UpdateResult. 83 func Update(c *gophercloud.ServiceClient, opts UpdateOptsBuilder) (r UpdateResult) { 84 h := make(map[string]string) 85 if opts != nil { 86 headers, err := opts.ToAccountUpdateMap() 87 if err != nil { 88 r.Err = err 89 return 90 } 91 for k, v := range headers { 92 h[k] = v 93 } 94 } 95 resp, err := c.Request("POST", updateURL(c), &gophercloud.RequestOpts{ 96 MoreHeaders: h, 97 OkCodes: []int{201, 202, 204}, 98 }) 99 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 100 return 101 }