forked from Scalingo/go-scalingo
/
logs-archives.go
89 lines (71 loc) · 1.86 KB
/
logs-archives.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package scalingo
import (
"encoding/json"
"io/ioutil"
"strconv"
"github.com/Scalingo/go-scalingo/http"
errgo "gopkg.in/errgo.v1"
)
type LogsArchivesService interface {
LogsArchivesByCursor(app string, cursor string) (*LogsArchivesResponse, error)
LogsArchives(app string, page int) (*LogsArchivesResponse, error)
}
var _ LogsArchivesService = (*Client)(nil)
type LogsArchiveItem struct {
Url string `json:"url"`
From string `json:"from"`
To string `json:"to"`
Size int64 `json:"size"`
}
type LogsArchivesResponse struct {
NextCursor string `json:"next_cursor"`
HasMore bool `json:"has_more"`
Archives []LogsArchiveItem `json:"archives"`
}
func (c *Client) LogsArchivesByCursor(app string, cursor string) (*LogsArchivesResponse, error) {
req := &http.APIRequest{
Endpoint: "/apps/" + app + "/logs_archives",
Params: map[string]string{
"cursor": cursor,
},
}
res, err := c.ScalingoAPI().Do(req)
if err != nil {
return nil, errgo.Mask(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, errgo.Mask(err)
}
var logsRes = LogsArchivesResponse{}
err = json.Unmarshal(body, &logsRes)
if err != nil {
return nil, errgo.Mask(err)
}
return &logsRes, nil
}
func (c *Client) LogsArchives(app string, page int) (*LogsArchivesResponse, error) {
if page < 1 {
return nil, errgo.New("Page must be greater than 0.")
}
req := &http.APIRequest{
Endpoint: "/apps/" + app + "/logs_archives",
Params: map[string]string{
"page": strconv.FormatInt(int64(page), 10),
},
}
res, err := c.ScalingoAPI().Do(req)
if err != nil {
return nil, errgo.Mask(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, errgo.Mask(err)
}
var logsRes = LogsArchivesResponse{}
err = json.Unmarshal(body, &logsRes)
if err != nil {
return nil, errgo.Mask(err)
}
return &logsRes, nil
}