Jamie Hannaford | 4baa123 | 2014-09-23 15:23:04 +0200 | [diff] [blame] | 1 | package gophercloud |
Jamie Hannaford | b3120f5 | 2014-09-23 15:17:57 +0200 | [diff] [blame] | 2 | |
| 3 | // CommonResult acts as a base struct that other results can embed. It contains |
Jamie Hannaford | 4baa123 | 2014-09-23 15:23:04 +0200 | [diff] [blame] | 4 | // the deserialized JSON structure returned from the server (Resp), and any |
Jamie Hannaford | b3120f5 | 2014-09-23 15:17:57 +0200 | [diff] [blame] | 5 | // errors that might have occurred during transport or deserialization. |
| 6 | type CommonResult struct { |
| 7 | Resp map[string]interface{} |
| 8 | Err error |
| 9 | } |
Ash Wilson | a6b0831 | 2014-10-02 15:27:45 -0400 | [diff] [blame] | 10 | |
| 11 | // RFC3339Milli describes a time format used by API responses. |
| 12 | const RFC3339Milli = "2006-01-02T15:04:05.999999Z" |
Jamie Hannaford | 369c9c6 | 2014-10-08 15:14:43 +0200 | [diff] [blame^] | 13 | |
| 14 | // Link represents a structure that enables paginated collections how to |
| 15 | // traverse backward or forward. The "Rel" field is usually either "next". |
| 16 | type Link struct { |
| 17 | Href string `mapstructure:"href"` |
| 18 | Rel string `mapstructure:"rel"` |
| 19 | } |
| 20 | |
| 21 | // ExtractNextURL attempts to extract the next URL from a JSON structure. It |
| 22 | // follows the common structure of nesting back and next links. |
| 23 | func ExtractNextURL(links []Link) (string, error) { |
| 24 | var url string |
| 25 | |
| 26 | for _, l := range links { |
| 27 | if l.Rel == "next" { |
| 28 | url = l.Href |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | if url == "" { |
| 33 | return "", nil |
| 34 | } |
| 35 | |
| 36 | return url, nil |
| 37 | } |