From 6ee3c9924114a22c883b26a816616d6d719f9f22 Mon Sep 17 00:00:00 2001 From: Bastian de Byl Date: Sun, 26 Feb 2023 01:57:05 -0500 Subject: [PATCH] added Put method --- helper.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/helper.go b/helper.go index 700e242..b6137ca 100644 --- a/helper.go +++ b/helper.go @@ -60,3 +60,28 @@ func Post(uri string, authName string, authValue string, data any) (*http.Respon return response, nil } + +func Put(uri string, authName string, authValue string, data any) (*http.Response, error) { + jsonBytes, err := json.Marshal(data) + if err != nil { + return nil, err + } + + body := bytes.NewBuffer(jsonBytes) + request, err := http.NewRequest("PUT", uri, body) + if err != nil { + return nil, err + } + + client := &http.Client{} + + request.Header.Set("Content-Type", "application/json") + request.Header.Set("Authorization", fmt.Sprintf("%s %s", authName, authValue)) + + response, err := client.Do(request) + if err != nil { + return nil, err + } + + return response, nil +}