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