示例#1
0
func (replay *ReplayDB) StoreRequestFromJson(path, method string, reqBody, respBody interface{}, statusCode int) {
	req := utils.JsonInterfaceToByte(reqBody)
	rsp := utils.JsonInterfaceToByte(respBody)

	err := replay.StoreRequest(path, method, string(req), string(rsp), statusCode)
	if err != nil {
		log.Println("Store for json failed ", err)
	}
}
示例#2
0
func (c *ProviderAPIClient) ClientRun(method, path string, reqBody interface{}) error {
	url := fmt.Sprintf("%s%s", c.baseURL, path)
	reqb := utils.JsonInterfaceToByte(reqBody)

	log.Println("going to verify: ", url+" "+method)

	req, err := http.NewRequest(method, url, bytes.NewBuffer(reqb))
	if err != nil {
		log.Println(err)
		return err
	}

	client := &http.Client{}
	resp, err := client.Do(req)

	if err != nil {
		log.Println(err)
		return err
	}
	defer resp.Body.Close()

	res, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Println("ioutil read err ", err, " body", string(res))
		return err
	}
	//log.Println("Got response: ", string(res))

	return nil
}