blob: f60bc762ab7dcfdf88235e751b15e3e477bba8bb [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 {
Ash Wilsond3dc2542014-10-20 10:10:48 -04007 // Body is the payload of the HTTP response from the server. In most cases, this will be the
8 // deserialized JSON structure.
9 Body interface{}
Ash Wilsoneab6a702014-10-20 08:18:30 -040010
Ash Wilson72e4d2c2014-10-20 10:27:30 -040011 // Header contains the HTTP header structure from the original response.
12 Header http.Header
Ash Wilsoneab6a702014-10-20 08:18:30 -040013
14 // Err is an error that occurred during the operation. It's deferred until extraction to make
15 // it easier to chain operations.
16 Err error
Jamie Hannafordb3120f52014-09-23 15:17:57 +020017}
Ash Wilsona6b08312014-10-02 15:27:45 -040018
19// RFC3339Milli describes a time format used by API responses.
20const RFC3339Milli = "2006-01-02T15:04:05.999999Z"
Jamie Hannaford369c9c62014-10-08 15:14:43 +020021
22// Link represents a structure that enables paginated collections how to
23// traverse backward or forward. The "Rel" field is usually either "next".
24type Link struct {
25 Href string `mapstructure:"href"`
26 Rel string `mapstructure:"rel"`
27}
28
29// ExtractNextURL attempts to extract the next URL from a JSON structure. It
30// follows the common structure of nesting back and next links.
31func ExtractNextURL(links []Link) (string, error) {
32 var url string
33
34 for _, l := range links {
35 if l.Rel == "next" {
36 url = l.Href
37 }
38 }
39
40 if url == "" {
41 return "", nil
42 }
43
44 return url, nil
45}