| | |
| | | import ( |
| | | "bytes" |
| | | "encoding/json" |
| | | "io/ioutil" |
| | | "errors" |
| | | "io" |
| | | "net/http" |
| | | "time" |
| | | ) |
| | |
| | | } |
| | | defer resp.Body.Close() |
| | | |
| | | respBytes, err := ioutil.ReadAll(resp.Body) |
| | | respBytes, err := io.ReadAll(resp.Body) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | return respBytes, nil |
| | | } |
| | | |
| | | func SendPostAndParseJson(url string, post, response interface{}) (err error) { |
| | | if response == nil { |
| | | return errors.New("response is not set") |
| | | } |
| | | |
| | | respBytes, err := SendPost(http.Header{}, url, post) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | return json.Unmarshal(respBytes, &response) |
| | | } |