add user service methods

This commit is contained in:
kandrusyak
2023-06-23 20:48:45 +03:00
parent 7d2aaf40e4
commit 7f4122360f
3 changed files with 100 additions and 6 deletions

View File

@@ -34,9 +34,57 @@ func PostRequest(url string, model any, header http.Header) ([]byte, error) {
return data, nil
}
func GetRequest(url string, header http.Header) ([]byte, error) {
func GetRequest(url string, header http.Header, args ...string) ([]byte, error) {
client := http.Client{}
req, err := http.NewRequest("GET", url, nil)
req.URL.RawQuery = args[0]
req.Header = header
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
return nil, err
}
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return data, nil
}
func PatchRequest(url string, model any, header http.Header) ([]byte, error) {
uJson, err := json.Marshal(model)
if err != nil {
return nil, err
}
client := http.Client{}
req, err := http.NewRequest("PATCH", url, bytes.NewReader(uJson))
req.Header = header
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
return nil, err
}
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return data, nil
}
func DeleteRequest(url string, header http.Header) ([]byte, error) {
client := http.Client{}
req, err := http.NewRequest("DELETE", url, nil)
req.Header = header
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)