-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
35 lines (33 loc) · 808 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package idpay
import (
"bytes"
"io"
"net/http"
"strconv"
)
func request(
apiKey string,
sandBox bool,
method string,
url string,
body []byte,
) (*int, []byte, error) {
request, err := http.NewRequest(method, url, bytes.NewBuffer(body))
if err != nil {
return nil, nil, err
}
request.Header.Set("Content-Type", "application/json")
request.Header.Set("X-API-KEY", apiKey)
request.Header.Set("X-SANDBOX", strconv.FormatBool(sandBox))
response, err := http.DefaultClient.Do(request)
if err != nil {
return nil, nil, err
}
defer response.Body.Close()
reponseBody, err := io.ReadAll(response.Body)
if err != nil {
return nil, nil, err
}
// fmt.Printf("response status code: %d\tresponse body: %s\n", response.StatusCode, reponseBody)
return &response.StatusCode, reponseBody, nil
}