From 8520a240816ec62f538b3d5edc7446037858166e Mon Sep 17 00:00:00 2001 From: yseto Date: Tue, 8 Nov 2022 12:56:39 +0900 Subject: [PATCH 1/4] UpdateAlert --- alerts.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/alerts.go b/alerts.go index 228b27e..cb5cbee 100644 --- a/alerts.go +++ b/alerts.go @@ -42,6 +42,7 @@ type Alert struct { Reason string `json:"reason,omitempty"` OpenedAt int64 `json:"openedAt,omitempty"` ClosedAt int64 `json:"closedAt,omitempty"` + Memo string `json:"memo,omitempty"` } // AlertsResp includes alert and next id @@ -50,6 +51,14 @@ type AlertsResp struct { NextID string `json:"nextId,omitempty"` } +// UpdateAlertParam is for UpdateAlert +type UpdateAlertParam struct { + Memo string `json:"memo,omitempty"` +} + +// UpdateAlertResponse is for UpdateAlert +type UpdateAlertResponse = UpdateAlertParam + func (c *Client) findAlertsWithParam(v url.Values) (*AlertsResp, error) { var d AlertsResp u := c.urlFor("/api/v0/alerts") @@ -138,3 +147,20 @@ func (c *Client) CloseAlert(alertID string, reason string) (*Alert, error) { return data, nil } + +// UpdateAlert updates a Alert +func (c *Client) UpdateAlert(alertID string, param UpdateAlertParam) (*UpdateAlertResponse, error) { + resp, err := c.PutJSON(fmt.Sprintf("/api/v0/alerts/%s", alertID), param) + defer closeResponse(resp) + if err != nil { + return nil, err + } + + var data = UpdateAlertResponse{} + err = json.NewDecoder(resp.Body).Decode(&data) + if err != nil { + return nil, err + } + + return &data, nil +} From 80d7e75ffe34910b6fbdb54d2c98b724c4bc840d Mon Sep 17 00:00:00 2001 From: yseto Date: Wed, 9 Nov 2022 11:24:24 +0900 Subject: [PATCH 2/4] fix types. --- alerts.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/alerts.go b/alerts.go index cb5cbee..d4564a4 100644 --- a/alerts.go +++ b/alerts.go @@ -57,7 +57,9 @@ type UpdateAlertParam struct { } // UpdateAlertResponse is for UpdateAlert -type UpdateAlertResponse = UpdateAlertParam +type UpdateAlertResponse struct { + Memo string `json:"memo,omitempty"` +} func (c *Client) findAlertsWithParam(v url.Values) (*AlertsResp, error) { var d AlertsResp From 9a3ca55275ddb683a28500c0e38b640eca727c61 Mon Sep 17 00:00:00 2001 From: yseto Date: Wed, 9 Nov 2022 11:33:16 +0900 Subject: [PATCH 3/4] Update alerts.go Co-authored-by: KADOTA, Kyohei --- alerts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alerts.go b/alerts.go index d4564a4..4e49c75 100644 --- a/alerts.go +++ b/alerts.go @@ -150,7 +150,7 @@ func (c *Client) CloseAlert(alertID string, reason string) (*Alert, error) { return data, nil } -// UpdateAlert updates a Alert +// UpdateAlert updates an Alert func (c *Client) UpdateAlert(alertID string, param UpdateAlertParam) (*UpdateAlertResponse, error) { resp, err := c.PutJSON(fmt.Sprintf("/api/v0/alerts/%s", alertID), param) defer closeResponse(resp) From 2e52f84f98a109dcbb9bf30402e469f2bdf874b1 Mon Sep 17 00:00:00 2001 From: yseto Date: Wed, 9 Nov 2022 11:33:22 +0900 Subject: [PATCH 4/4] Update alerts.go Co-authored-by: KADOTA, Kyohei --- alerts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alerts.go b/alerts.go index 4e49c75..e27a70c 100644 --- a/alerts.go +++ b/alerts.go @@ -158,7 +158,7 @@ func (c *Client) UpdateAlert(alertID string, param UpdateAlertParam) (*UpdateAle return nil, err } - var data = UpdateAlertResponse{} + var data UpdateAlertResponse err = json.NewDecoder(resp.Body).Decode(&data) if err != nil { return nil, err