blob: 902260a854243e7d6bd31350ff0a3d3066b5d016 [file] [log] [blame]
Jamie Hannaford4baa1232014-09-23 15:23:04 +02001package gophercloud
Jamie Hannafordb3120f52014-09-23 15:17:57 +02002
Ash Wilsoneab6a702014-10-20 08:18:30 -04003import "net/http"
4
5// Result acts as a base struct that other results can embed.
6type Result struct {
7 // Resp is the deserialized JSON structure returned from the server.
Jamie Hannafordb3120f52014-09-23 15:17:57 +02008 Resp map[string]interface{}
Ash Wilsoneab6a702014-10-20 08:18:30 -04009
10 // Headers contains the HTTP header structure from the original response.
11 Headers http.Header
12
13 // Err is an error that occurred during the operation. It's deferred until extraction to make
14 // it easier to chain operations.
15 Err error
Jamie Hannafordb3120f52014-09-23 15:17:57 +020016}
Ash Wilsona6b08312014-10-02 15:27:45 -040017
18// RFC3339Milli describes a time format used by API responses.
19const RFC3339Milli = "2006-01-02T15:04:05.999999Z"
Jamie Hannaford369c9c62014-10-08 15:14:43 +020020
21// Link represents a structure that enables paginated collections how to
22// traverse backward or forward. The "Rel" field is usually either "next".
23type Link struct {
24 Href string `mapstructure:"href"`
25 Rel string `mapstructure:"rel"`
26}
27
28// ExtractNextURL attempts to extract the next URL from a JSON structure. It
29// follows the common structure of nesting back and next links.
30func ExtractNextURL(links []Link) (string, error) {
31 var url string
32
33 for _, l := range links {
34 if l.Rel == "next" {
35 url = l.Href
36 }
37 }
38
39 if url == "" {
40 return "", nil
41 }
42
43 return url, nil
44}