-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlogs-archives.go
More file actions
67 lines (54 loc) · 1.68 KB
/
logs-archives.go
File metadata and controls
67 lines (54 loc) · 1.68 KB
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
package scalingo
import (
"context"
"strconv"
"github.com/Scalingo/go-scalingo/v11/http"
"github.com/Scalingo/go-utils/errors/v3"
)
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) {
var logsRes LogsArchivesResponse
req := &http.APIRequest{
Endpoint: "/apps/" + app + "/logs_archives",
Params: map[string]string{
"cursor": cursor,
},
}
err := c.ScalingoAPI().DoRequest(ctx, req, &logsRes)
if err != nil {
return nil, errors.Wrap(ctx, err, "list logs archives by cursor")
}
return &logsRes, nil
}
func (c *Client) LogsArchives(ctx context.Context, app string, page int) (*LogsArchivesResponse, error) {
if page < 1 {
return nil, errors.New(ctx, "Page must be greater than 0.")
}
req := &http.APIRequest{
Endpoint: "/apps/" + app + "/logs_archives",
Params: map[string]string{
"page": strconv.FormatInt(int64(page), 10),
},
}
var logsRes LogsArchivesResponse
err := c.ScalingoAPI().DoRequest(ctx, req, &logsRes)
if err != nil {
return nil, errors.Wrap(ctx, err, "list logs archives")
}
return &logsRes, nil
}