add new endpoints

This commit is contained in:
andrusyakka
2023-08-15 17:47:31 +03:00
parent fe85ad5fe8
commit 932aaef2fc
4 changed files with 148 additions and 21 deletions

View File

@@ -1,8 +1,6 @@
package api
import (
"bytes"
"encoding/json"
"io"
"net/http"
)
@@ -50,31 +48,24 @@ func GetRequest(url string, header http.Header, args ...string) ([]byte, error,
return data, nil, resp
}
func PatchRequest(url string, model any, header http.Header) ([]byte, error) {
uJson, err := json.Marshal(model)
if err != nil {
return nil, err
}
func PatchRequest(url string, body io.Reader, header http.Header) ([]byte, error, *http.Response) {
client := http.Client{}
req, err := http.NewRequest("PATCH", url, bytes.NewReader(uJson))
req, err := http.NewRequest("POST", url, body)
req.Header = header
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
return nil, err
return nil, err, resp
}
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
return nil, err, resp
}
return data, nil
return data, nil, resp
}
func DeleteRequest(url string, header http.Header) ([]byte, error, *http.Response) {