From b432266486926ec9a6f66004d7e2ecf5434d1bdb Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 16 Oct 2024 13:50:09 +0200 Subject: [PATCH] callPut --- tools/remote_caller.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/remote_caller.go b/tools/remote_caller.go index c28b1f2..986819f 100644 --- a/tools/remote_caller.go +++ b/tools/remote_caller.go @@ -84,4 +84,20 @@ func (caller *HTTPCaller) CallPost(url string, subpath string, body map[string]i return io.ReadAll(resp.Body) } -// NO PUT IN HERE TO DANGEROUS TO USE ON A REMOTE SERVER, MAYBE NEEDED IN THE FUTURE +// CallPost calls the POST method on the HTTP server +func (caller *HTTPCaller) CallPut(url string, subpath string, body map[string]interface{}) ([]byte, error) { + postBody, _ := json.Marshal(body) + responseBody := bytes.NewBuffer(postBody) + req, err := http.NewRequest(http.MethodPut, url+subpath, responseBody) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", "application/json") + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + return io.ReadAll(resp.Body) +}