| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package govcd |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
|
| 10 |
types "github.com/hmrc/vmware-govcd/types/v56" |
| 11 |
) |
| 12 |
|
| 13 |
type Results struct { |
| 14 |
Results *types.QueryResultRecordsType |
| 15 |
c *Client |
| 16 |
} |
| 17 |
|
| 18 |
func NewResults(c *Client) *Results { |
| 19 |
return &Results{ |
| 20 |
Results: new(types.QueryResultRecordsType), |
| 21 |
c: c, |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
func (c *VCDClient) Query(params map[string]string) (Results, error) { |
| 26 |
|
| 27 |
req := c.Client.NewRequest(params, "GET", c.QueryHREF, nil) |
| 28 |
req.Header.Add("Accept", "vnd.vmware.vcloud.org+xml;version=5.5") |
| 29 |
|
| 30 |
resp, err := checkResp(c.Client.Http.Do(req)) |
| 31 |
if err != nil { |
| 32 |
return Results{}, fmt.Errorf("error retreiving query: %s", err) |
| 33 |
} |
| 34 |
|
| 35 |
results := NewResults(&c.Client) |
| 36 |
|
| 37 |
if err = decodeBody(resp, results.Results); err != nil { |
| 38 |
return Results{}, fmt.Errorf("error decoding query results: %s", err) |
| 39 |
} |
| 40 |
|
| 41 |
return *results, nil |
| 42 |
} |