Ejemplo n.º 1
0
func convert(goResp Response) *http.Response {
	if goResp == nil {
		return nil
	}
	httpResp := http.Response(*goResp)
	return &httpResp
}
Ejemplo n.º 2
0
func (client *Client) Get(url string, params interface{}, result interface{}) (*http.Response, []byte, error) {
	client.req.TargetType = "json"
	resp, body, errSlice := client.req.Get(url).Query(params).EndBytes()
	if errSlice != nil && len(errSlice) > 0 {
		return nil, body, errSlice[len(errSlice)-1]
	}
	err := unmarshallResponse(resp, body, result)
	_resp := http.Response(*resp)
	return &_resp, body, err
}
Ejemplo n.º 3
0
func (client *Client) Create(url string, content interface{}, result interface{}) (*http.Response, []byte, error) {
	contentVal := unpackInterfacePointer(content)
	client.req.TargetType = "json"
	req := client.req.Post(url).Send(contentVal)
	resp, body, errSlice := req.EndBytes()
	if errSlice != nil && len(errSlice) > 0 {
		return nil, body, errSlice[len(errSlice)-1]
	}
	err := unmarshallResponse(resp, body, result)
	_resp := http.Response(*resp)
	return &_resp, body, err
}
Ejemplo n.º 4
0
func (client *Client) Delete(url string, params interface{}, result interface{}) (*http.Response, []byte, error) {
	client.req.TargetType = "json"
	req := client.req.Get(url).Query(params).Query("_method=DELETE")
	req.Set("HTTP_X_HTTP_METHOD_OVERRIDE", "DELETE")
	resp, body, errSlice := req.End()
	by := []byte(body)
	if errSlice != nil && len(errSlice) > 0 {
		return resp, by, errSlice[len(errSlice)-1]
	}
	err := unmarshallResponse(resp, by, result)
	_resp := http.Response(*resp)
	return &_resp, by, err
}
Ejemplo n.º 5
0
func (client *Client) PostData(url string, content []byte, contentType string, filename string, result interface{}) (*http.Response, []byte, error) {

	// gorequest does not support POST-ing raw data
	// so, we have to manually create a HTTP client
	s := client.req.Post(url)

	buf := bytes.NewBuffer(content)

	req, err := http.NewRequest(s.Method, s.Url, buf)
	if err != nil {
		return nil, nil, err
	}

	req.Header.Set("Content-Type", contentType)
	req.Header.Set("Content-Disposition", fmt.Sprintf("filename=%v", filename))

	// Add basic auth
	req.SetBasicAuth(s.BasicAuth.Username, s.BasicAuth.Password)

	// Set Transport
	s.Client.Transport = s.Transport

	// Send request
	resp, err := s.Client.Do(req)
	if err != nil {
		return nil, nil, err
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, nil, err
	}

	err = unmarshallResponse(resp, body, result)
	_resp := http.Response(*resp)
	return &_resp, body, err
}
Ejemplo n.º 6
0
func (e HTTPError) Error() string {
	return fmt.Sprintf("HTTP error: %v", http.Response(e).StatusCode)
}
Ejemplo n.º 7
0
func (f fakeHttp) RoundTrip(*http.Request) (*http.Response, error) {
	p := http.Response(f)
	return &p, nil
}