blob: 8ec2eff415b81266e23c265490563a7f2c5e6910 [file] [log] [blame]
Jamie Hannaford93209fe2014-10-10 11:54:19 +02001package accounts
2
3import (
4 "net/http"
5 "strings"
Jamie Hannafordb2e129d2014-10-10 14:06:28 +02006
7 "github.com/rackspace/gophercloud"
Jamie Hannaford93209fe2014-10-10 11:54:19 +02008)
9
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020010type commonResult struct {
11 gophercloud.CommonResult
12 Resp *http.Response
13}
14
15// GetResult represents the result of a create operation.
16type GetResult struct {
17 commonResult
18}
19
20// UpdateResult represents the result of an update operation.
21type UpdateResult struct {
22 commonResult
23}
Jamie Hannaford93209fe2014-10-10 11:54:19 +020024
25// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
26// and returns the custom metatdata associated with the account.
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020027func (res commonResult) ExtractMetadata() map[string]string {
Jamie Hannaford93209fe2014-10-10 11:54:19 +020028 metadata := make(map[string]string)
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020029
30 for k, v := range res.Resp.Header {
Jamie Hannaford93209fe2014-10-10 11:54:19 +020031 if strings.HasPrefix(k, "X-Account-Meta-") {
32 key := strings.TrimPrefix(k, "X-Account-Meta-")
33 metadata[key] = v[0]
34 }
35 }
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020036
Jamie Hannaford93209fe2014-10-10 11:54:19 +020037 return metadata
38}