add header filter
This commit is contained in:
@@ -7,15 +7,39 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func PostRequest(url string, model any) ([]byte, error) {
|
||||
func PostRequest(url string, model any, header http.Header) ([]byte, error) {
|
||||
uJson, err := json.Marshal(model)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := http.Post(url,
|
||||
"application/json", bytes.NewReader(uJson))
|
||||
client := http.Client{}
|
||||
req, err := http.NewRequest("POST", 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 GetRequest(url string, header http.Header) ([]byte, error) {
|
||||
client := http.Client{}
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
req.Header = header
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user