2024-03-25 11:55:01 +02:00
|
|
|
package monobank
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Request(method string, url string, data interface{}) (string, error) {
|
|
|
|
apiMonabankToken := os.Getenv("MONOBANK_TOKEN")
|
|
|
|
|
|
|
|
json, err := json.Marshal(data)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := http.NewRequest(method, url, bytes.NewBuffer(json))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2024-03-27 19:06:44 +02:00
|
|
|
r.Header.Add("Accept", "application/vnd.api+json")
|
2024-03-25 11:55:01 +02:00
|
|
|
r.Header.Add("Content-Type", "application/json")
|
|
|
|
r.Header.Add("X-Token", apiMonabankToken)
|
|
|
|
|
|
|
|
client := &http.Client{}
|
|
|
|
res, err := client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
|
|
body, _ := io.ReadAll(res.Body)
|
|
|
|
return string(body), nil
|
|
|
|
}
|