-
Notifications
You must be signed in to change notification settings - Fork 8
/
logs-archives.go
92 lines (74 loc) · 1.99 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
90
91
92
package scalingo
import (
"context"
"encoding/json"
"io"
"strconv"
"gopkg.in/errgo.v1"
"github.com/Scalingo/go-scalingo/v7/http"
)
type LogsArchivesService interface {
LogsArchivesByCursor(ctx context.Context, app string, cursor string) (*LogsArchivesResponse, error)
LogsArchives(ctx context.Context, 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(ctx context.Context, 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(ctx, req)
if err != nil {
return nil, errgo.Mask(err)
}
defer res.Body.Close()
body, err := io.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(ctx context.Context, 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(ctx, req)
if err != nil {
return nil, errgo.Mask(err)
}
defer res.Body.Close()
body, err := io.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
}