Струтуризация и сделан пропуск вопросов

This commit is contained in:
Anatoly Prohacky
2023-01-18 23:35:07 +10:00
parent 93afb8d15b
commit 96f75155ba
10 changed files with 213 additions and 0 deletions

34
pkg/util/download.go Normal file
View File

@@ -0,0 +1,34 @@
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
}