2025-12-26 17:38:20 +03:00

32 lines
530 B
Go

package utils
import (
"bytes"
"encoding/json"
"io"
"net/http"
)
func MakeRequest(method, url string, body interface{}) (*http.Response, error) {
var reqBody io.Reader
if body != nil {
jsonBody, err := json.Marshal(body)
if err != nil {
return nil, err
}
reqBody = bytes.NewBuffer(jsonBody)
}
req, err := http.NewRequest(method, url, reqBody)
if err != nil {
return nil, err
}
if body != nil {
req.Header.Set("Content-Type", "application/json")
}
client := &http.Client{}
return client.Do(req)
}