add user service methods
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user