brightbox.go
func (c *Client) MakeApiRequest(method string, path string, reqBody interface{}, resBody interface{}) (*http.Response, error) {
	req, err := c.NewRequest(method, path, reqBody)
	if err != nil {
		return nil, err
	}
	res, err := c.client.Do(req)
	if err != nil {
		return res, err
	}
	defer res.Body.Close()
	if res.StatusCode >= 200 && res.StatusCode <= 299 {
		if resBody != nil {
			err := json.NewDecoder(res.Body).Decode(resBody)
			if err != nil {
				return res, ApiError{
					RequestUrl: res.Request.URL,
					StatusCode: res.StatusCode,
					Status:     res.Status,
					ParseError: &err,
				}
			}
		}
		return res, nil
	} else {
		apierr := ApiError{
			RequestUrl: res.Request.URL,
			StatusCode: res.StatusCode,
			Status:     res.Status,
		}
		body, _ := ioutil.ReadAll(res.Body)
		err = json.Unmarshal(body, &apierr)
		apierr.ResponseBody = body
		return res, apierr
	}
}
func (c *Client) MakeApiRequest(method string, path string, reqBody interface{}, resBody interface{}) (*http.Response, error) {
	req, err := c.NewRequest(method, path, reqBody)
	if err != nil {
		return nil, err
	}
	res, err := c.client.Do(req)
	if err != nil {
		return res, err
	}
	defer res.Body.Close()
	if res.StatusCode >= 200 && res.StatusCode <= 299 {
		if resBody != nil {
			err := json.NewDecoder(res.Body).Decode(resBody)
			if err != nil {
				return res, ApiError{
					RequestUrl: res.Request.URL,
					StatusCode: res.StatusCode,
					Status:     res.Status,
					ParseError: &err,
				}
			}
		}
		return res, nil
	} else {
		apierr := ApiError{
			RequestUrl: res.Request.URL,
			StatusCode: res.StatusCode,
			Status:     res.Status,
		}
		body, _ := ioutil.ReadAll(res.Body)
		err = json.Unmarshal(body, &apierr)
		apierr.ResponseBody = body
		return res, apierr
	}
}
func ( c * Client ) MakeApiRequest ( method string , path string , reqBody interface { } , resBody interface { } ) ( * http . Response , error ) { req , err := c . NewRequest ( method , path , reqBody ) if err != nil { return nil , err } res , err := c . client . Do ( req ) if err != nil { return res , err } defer res . Body . Close ( ) if res . StatusCode >= 200 && res . StatusCode <= 299 { if resBody != nil { err := json . NewDecoder ( res . Body ) . Decode ( resBody ) if err != nil { return res , ApiError { RequestUrl : res . Request . URL , StatusCode : res . StatusCode , Status : res . Status , ParseError : & err , } } } return res , nil } else { apierr := ApiError { RequestUrl : res . Request . URL , StatusCode : res . StatusCode , Status : res . Status , } body , _ := ioutil . ReadAll ( res . Body ) err = json . Unmarshal ( body , & apierr ) apierr . ResponseBody = body return res , apierr } }
// MakeApiRequest makes a http request to the API, JSON encoding any given data
// and decoding any JSON reponse.
//
// method should be the desired http method, e.g: "GET", "POST", "PUT" etc.
//
// urlStr should be the url path, relative to the api url e.g: "/1.0/servers"
//
// if reqBody is non-nil, it will be Marshaled to JSON and set as the request
// body.
//
// Optionally, the response body will be Unmarshaled from JSON into whatever
// resBody is a pointer to. Leave nil to skip.
//
// If the response is non-2xx, MakeApiRequest will try to parse the error
// message and return an ApiError struct.
MakeApiRequest makes a http request to the API JSON encoding any given data and decoding any JSON reponse . method should be the desired http method e . g : GET POST PUT etc . urlStr should be the url path relative to the api url e . g : / 1 . 0 / servers if reqBody is non - nil it will be Marshaled to JSON and set as the request body . Optionally the response body will be Unmarshaled from JSON into whatever resBody is a pointer to . Leave nil to skip . If the response is non - 2xx MakeApiRequest will try to parse the error message and return an ApiError struct .