blob: abae02659cf57fdee37d6b7699299d8a9d7e54a7 [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
Ash Wilsonaf262872014-10-20 09:32:29 -04006 "github.com/rackspace/gophercloud"
Jamie Hannaford93209fe2014-10-10 11:54:19 +02007)
8
Ash Wilsonaf262872014-10-20 09:32:29 -04009// GetResult is returned from a call to the Get function.
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020010type GetResult struct {
Jon Perrittd50f93e2014-10-27 14:19:27 -050011 gophercloud.HeaderResult
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)
Ash Wilson72e4d2c2014-10-20 10:27:30 -040022 for k, v := range gr.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
Ash Wilsonaf262872014-10-20 09:32:29 -040031// UpdateResult is returned from a call to the Update function.
Jon Perritt4a59d232014-10-09 20:21:31 -050032type UpdateResult struct {
Jon Perrittd50f93e2014-10-27 14:19:27 -050033 gophercloud.HeaderResult
Ash Wilsonaf262872014-10-20 09:32:29 -040034}