mchstest/pkg/util/download.go

35 lines
537 B
Go
Raw Normal View History

package util
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"github.com/google/uuid"
)
func ReqestToSiteJSON(req any, url string, uid uuid.UUID) ([]byte, error) {
reqBodyBytes, err := json.Marshal(req)
if err != nil {
return nil, err
}
urlr := url + uid.String()
resp, err := http.Post(
urlr,
"application/json", bytes.NewBuffer(reqBodyBytes))
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, nil
}