add events

This commit is contained in:
andrusyakka
2023-07-17 14:30:22 +03:00
parent 9234b577bb
commit c8ce5a910e
5 changed files with 99 additions and 29 deletions

View File

@@ -7,31 +7,25 @@ import (
"net/http"
)
func PostRequest(url string, model any, header http.Header) ([]byte, error) {
uJson, err := json.Marshal(model)
if err != nil {
return nil, err
}
func PostRequest(url string, body io.Reader, header http.Header) ([]byte, error, *http.Response) {
client := http.Client{}
req, err := http.NewRequest("POST", 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 GetRequest(url string, header http.Header, args ...string) ([]byte, error, *http.Response) {
@@ -84,7 +78,7 @@ func PatchRequest(url string, model any, header http.Header) ([]byte, error) {
return data, nil
}
func DeleteRequest(url string, header http.Header) ([]byte, error) {
func DeleteRequest(url string, header http.Header) ([]byte, error, *http.Response) {
client := http.Client{}
req, err := http.NewRequest("DELETE", url, nil)
req.Header = header
@@ -92,14 +86,14 @@ func DeleteRequest(url string, header http.Header) ([]byte, error) {
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
}