Ejemplo n.º 1
0
// makePostRequest shim performs a POST request, checking for a positive outcome.
// See simplehttp.MakePostRequest for more details.
func makePostRequest(r *simplehttp.HTTPRequest, p simplehttp.Payload) (*simplehttp.HTTPResponse, error) {
	r.AddHeader("User-Agent", MailgunGoUserAgent)
	rsp, err := r.MakePostRequest(p)
	if (err == nil) && notGood(rsp.Code, expected) {
		return rsp, newError(r.URL, expected, rsp.Code)
	}
	return rsp, err
}
Ejemplo n.º 2
0
// postResponseFromJSON shim performs a POST request, checking for a positive outcome.
// See simplehttp.PostResponseFromJSON for more details.
func postResponseFromJSON(r *simplehttp.HTTPRequest, p simplehttp.Payload, v interface{}) error {
	r.AddHeader("User-Agent", MailgunGoUserAgent)
	response, err := r.MakePostRequest(p)
	if err != nil {
		return err
	}
	if notGood(response.Code, expected) {
		return newError(r.URL, expected, response.Code)
	}
	return response.ParseFromJSON(v)
}