blob: 8ff8183d5c6634455d96a3e6fa3693d46032a8e2 [file] [log] [blame]
Jamie Hannaford93209fe2014-10-10 11:54:19 +02001package accounts
2
3import (
Jamie Hannaford93209fe2014-10-10 11:54:19 +02004 "strings"
Jamie Hannafordb2e129d2014-10-10 14:06:28 +02005
Jon Perritt4a59d232014-10-09 20:21:31 -05006 objectstorage "github.com/rackspace/gophercloud/openstack/objectstorage/v1"
Jamie Hannaford93209fe2014-10-10 11:54:19 +02007)
8
Jon Perritt4a59d232014-10-09 20:21:31 -05009// GetResult is returned from a call to the Get function. See v1.CommonResult.
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020010type GetResult struct {
Jon Perritt4a59d232014-10-09 20:21:31 -050011 objectstorage.CommonResult
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020012}
Jamie Hannaford93209fe2014-10-10 11:54:19 +020013
14// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
15// and returns the custom metatdata associated with the account.
Jon Perritt4a59d232014-10-09 20:21:31 -050016func (gr GetResult) ExtractMetadata() (map[string]string, error) {
17 if gr.Err != nil {
18 return nil, gr.Err
19 }
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020020
Jon Perritt4a59d232014-10-09 20:21:31 -050021 metadata := make(map[string]string)
22 for k, v := range gr.Resp.Header {
Jamie Hannaford93209fe2014-10-10 11:54:19 +020023 if strings.HasPrefix(k, "X-Account-Meta-") {
24 key := strings.TrimPrefix(k, "X-Account-Meta-")
25 metadata[key] = v[0]
26 }
27 }
Jon Perritt4a59d232014-10-09 20:21:31 -050028 return metadata, nil
29}
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020030
Jon Perritt4a59d232014-10-09 20:21:31 -050031// UpdateResult is returned from a call to the Update function. See v1.CommonResult.
32type UpdateResult struct {
33 objectstorage.CommonResult
Jamie Hannaford93209fe2014-10-10 11:54:19 +020034}