-
Notifications
You must be signed in to change notification settings - Fork 0
/
listtemplates.go
41 lines (36 loc) · 914 Bytes
/
listtemplates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cloudatgost
import(
"net/http"
"net/url"
)
// A TemplateList represents an API response for machine templates
// currently available.
type TemplateList struct {
Status string `json:"status"`
Time int `json:"time"`
Data []struct {
ID string `json:"id"`
Detail string `json:"detail"`
} `json:"data"`
}
// ListTemplates formulates an HTTP request to the listtemplates.php
// endpoint and maps the JSON response through Do to a TemplateList
// structure.
func (c *Client) ListTemplates() (*TemplateList) {
v := &TemplateList{}
URL, err := url.Parse(c.BaseURL)
if err != nil {
panic("boom! Busted :F")
}
URL.Path += "listtemplates.php"
parameters := url.Values{}
parameters.Add("key", c.Token)
parameters.Add("login", c.Login)
URL.RawQuery = parameters.Encode()
request, err := http.NewRequest("GET", URL.String(), nil)
if err != nil {
return nil
}
c.Do(request, &v)
return v
}