Skip to content

Commit

Permalink
Add AddonLogsArchives implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sihamais authored and EtienneM committed Nov 5, 2021
1 parent 59d9900 commit 2f85193
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## To Be Released

* feat: add support to list container sizes [#234](https://github.com/Scalingo/go-scalingo/pull/234)
* feat(apps): add AppsRouterLogs function [#236](https://github.com/Scalingo/go-scalingo/pull/236)
* feat(addons): add the `AddonLogsArchives` method [#235](https://github.com/Scalingo/go-scalingo/pull/235)
* feat(apps): add `AppsRouterLogs` method [#236](https://github.com/Scalingo/go-scalingo/pull/236)

## 4.14.3

Expand Down
28 changes: 28 additions & 0 deletions addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package scalingo

import (
"encoding/json"
"io/ioutil"
"strconv"
"time"

"github.com/Scalingo/go-scalingo/v4/http"
Expand All @@ -16,6 +18,7 @@ type AddonsService interface {
AddonUpgrade(app, addonID string, params AddonUpgradeParams) (AddonRes, error)
AddonToken(app, addonID string) (string, error)
AddonLogsURL(app, addonID string) (string, error)
AddonLogsArchives(app, addonId string, page int)(*LogsArchivesResponse, error)
}

var _ AddonsService = (*Client)(nil)
Expand Down Expand Up @@ -154,3 +157,28 @@ func (c *Client) AddonLogsURL(app, addonID string) (string, error) {

return url.URL, nil
}

func (c *Client) AddonLogsArchives(app, addonID string, page int) (*LogsArchivesResponse, error) {
res, err := c.DBAPI(app, addonID).Do(&http.APIRequest{
Endpoint: "/databases/" + addonID + "/logs_archives",
Params: map[string]string{
"page": strconv.FormatInt(int64(page), 10),
},
})
if err != nil {
return nil, errgo.Notef(err, "fail to get log archives")
}

body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, errgo.Notef(err, "fail to read body of response")
}

var logsRes = LogsArchivesResponse{}
err = json.Unmarshal(body, &logsRes)
if err != nil {
return nil, errgo.Notef(err, "fail to parse response")
}

return &logsRes, nil
}

0 comments on commit 2f85193

Please sign in to comment.