-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists.go
More file actions
38 lines (31 loc) · 746 Bytes
/
lists.go
File metadata and controls
38 lines (31 loc) · 746 Bytes
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
package loops
import (
"encoding/json"
"fmt"
"net/http"
)
type MailingList struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
IsPublic bool `json:"isPublic"`
}
func (c *Client) ListMailingLists() ([]MailingList, error) {
req, err := c.newRequest(http.MethodGet, "/lists", nil)
if err != nil {
return nil, err
}
resp, err := c.do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errorFromResponse(resp)
}
var result []MailingList
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return nil, fmt.Errorf("failed to decode response: %w", err)
}
return result, nil
}