From 6faebaa9dd6a6c6bf803632adf91eee2719f7fb0 Mon Sep 17 00:00:00 2001 From: yseto Date: Tue, 16 Jul 2024 12:38:07 +0900 Subject: [PATCH] revert PostJSON, PutJSON refer https://github.com/mackerelio/mackerel-client-go/releases/tag/v0.27.0 --- mackerel.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mackerel.go b/mackerel.go index 13b6b30..65117e2 100644 --- a/mackerel.go +++ b/mackerel.go @@ -194,3 +194,28 @@ func requestInternal[T any](client *Client, method, path string, params url.Valu } return &data, resp.Header, nil } + +func (c *Client) compatRequestJSON(method string, path string, payload interface{}) (*http.Response, error) { + var body bytes.Buffer + err := json.NewEncoder(&body).Encode(payload) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(method, c.urlFor(path, url.Values{}).String(), &body) + if err != nil { + return nil, err + } + req.Header.Add("Content-Type", "application/json") + return c.Request(req) +} + +// Deprecated: use other prefered method. +func (c *Client) PostJSON(path string, payload interface{}) (*http.Response, error) { + return c.compatRequestJSON(http.MethodPost, path, payload) +} + +// Deprecated: use other prefered method. +func (c *Client) PutJSON(path string, payload interface{}) (*http.Response, error) { + return c.compatRequestJSON(http.MethodPut, path, payload) +}