FixUnlinkedURL() (and improve HasUnlinkedURL())

This commit is contained in:
Ian Gulliver
2021-09-19 06:49:00 +00:00
parent 5b2f3d5d3e
commit 034108a785
4 changed files with 157 additions and 9 deletions

View File

@@ -116,14 +116,26 @@ func (c *Client) get(path string, values *url.Values, out interface{}) error {
}
func (c *Client) post(path string, body interface{}, out interface{}) error {
return c.doWithBody("POST", path, body, out)
}
func (c *Client) put(path string, body interface{}, out interface{}) error {
return c.doWithBody("PUT", path, body, out)
}
func (c *Client) doWithBody(method string, path string, body interface{}, out interface{}) error {
url := fmt.Sprintf("%s%s", baseURL, path)
enc, err := json.Marshal(body)
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
err := enc.Encode(body)
if err != nil {
return err
}
req, err := http.NewRequest("POST", url, bytes.NewReader(enc))
req, err := http.NewRequest(method, url, buf)
if err != nil {
return err
}