// Do runs a request with our client.
775867
func (c *Client) Do(ctx context.Context, r *Request) (*http.Response, error) {
	req, err := r.toHTTP(ctx, c.config)
	if err != nil {
		return nil, err
	}
	c.logRequest(req)
	resp, err := c.config.HTTPClient.Do(req)
	c.logResponse(resp)
	return resp, err
}
1095710
func (c *Client) Do(ctx context.Context, req *http.Request, resBody interface{}) error {
	switch req.Method {
	case http.MethodPost, http.MethodPatch:
		req.Header.Set("Content-Type", "application/json")
	}

	req.Header.Set("Accept", "application/json")

	if s, ok := ctx.Value(signerContext{}).(Signer); ok {
		if err := s.SignRequest(req); err != nil {
			return err
		}
	}

	return c.Client.Do(ctx, req, func(res *http.Response) error {
		switch res.StatusCode {
		case http.StatusOK:
		case http.StatusBadRequest:
			// TODO: structured error types
			detail, err := ioutil.ReadAll(res.Body)
			if err != nil {
				return err
			}
			return fmt.Errorf("%s: %s", res.Status, bytes.TrimSpace(detail))
		default:
			return fmt.Errorf("%s %s: %s", req.Method, req.URL, res.Status)
		}

		if resBody == nil {
			return nil
		}

		switch b := resBody.(type) {
		case io.Writer:
			_, err := io.Copy(b, res.Body)
			return err
		default:
			val := struct {
				Value interface{} `json:"value,omitempty"`
			}{
				resBody,
			}
			return json.NewDecoder(res.Body).Decode(&val)
		}
	})
}
1359524
func (b *UpdateService) Do(ctx context.Context) (*UpdateResponse, error) {
	path, params, err := b.url()
	if err != nil {
		return nil, err
	}

	// Get body of the request
	body, err := b.body()
	if err != nil {
		return nil, err
	}

	// Get response
	res, err := b.client.PerformRequest(ctx, PerformRequestOptions{
		Method: "POST",
		Path:   path,
		Params: params,
		Body:   body,
	})
	if err != nil {
		return nil, err
	}

	// Return result
	ret := new(UpdateResponse)
	if err := b.client.decoder.Decode(res.Body, ret); err != nil {
		return nil, err
	}
	return ret, nil
}
212510
func (c *Client) Do(opts interface{}) (interface{}, error) {
	// Bucket
	if _, ok := opts.(*RpbListKeysReq); ok {
		return c.listKeys(opts.(*RpbListKeysReq), string(opts.(*RpbListKeysReq).GetBucket()))
	}
	if _, ok := opts.(*RpbGetBucketReq); ok {
		return c.getBucket(opts.(*RpbGetBucketReq), string(opts.(*RpbGetBucketReq).GetBucket()))
	}
	if _, ok := opts.(*RpbSetBucketReq); ok {
		nval := opts.(*RpbSetBucketReq).Props.GetNVal()
		allowMulti := opts.(*RpbSetBucketReq).Props.GetAllowMult()
		return c.setBucket(opts.(*RpbSetBucketReq), string(opts.(*RpbSetBucketReq).GetBucket()), &nval, &allowMulti)
	}

	// Object
	if _, ok := opts.(*RpbGetReq); ok {
		return c.fetchObject(opts.(*RpbGetReq), string(opts.(*RpbGetReq).GetBucket()), string(opts.(*RpbGetReq).GetKey()))
	}
	if _, ok := opts.(*RpbDelReq); ok {
		return c.deleteObject(opts.(*RpbDelReq), string(opts.(*RpbDelReq).GetBucket()), string(opts.(*RpbDelReq).GetKey()))
	}

	// Query
	if _, ok := opts.(*RpbMapRedReq); ok {
		return c.mapReduce(opts.(*RpbMapRedReq), string(opts.(*RpbMapRedReq).GetRequest()), string(opts.(*RpbMapRedReq).GetContentType()))
	}
	if _, ok := opts.(*RpbIndexReq); ok {
		return c.index(opts.(*RpbIndexReq), string(opts.(*RpbIndexReq).GetBucket()), string(opts.(*RpbIndexReq).GetIndex()), string(opts.(*RpbIndexReq).GetKey()), string(opts.(*RpbIndexReq).GetRangeMin()), string(opts.(*RpbIndexReq).GetRangeMax()))
	}
	if _, ok := opts.(*RpbSearchQueryReq); ok {
		return c.search(opts.(*RpbSearchQueryReq), string(opts.(*RpbSearchQueryReq).GetIndex()), string(opts.(*RpbSearchQueryReq).GetQ()))
	}

	// Server
	if _, ok := opts.(*RpbSetClientIdReq); ok {
		return c.setClientId(opts.(*RpbSetClientIdReq), string(opts.(*RpbSetClientIdReq).GetClientId()))
	}

	return nil, nil
}
803256
func (f doFunc) Do(ctx context.Context, req *http.Request) (*http.Response, error) {
	return f(ctx, req)
}
1271828
func (r *Request) Do() bool {
	if r.do != 0 {
		return r.do == doTrue
	}

	if o := r.Req.IsEdns0(); o != nil {
		if o.Do() {
			r.do = doTrue
		} else {
			r.do = doFalse
		}
		return o.Do()
	}
	r.do = doFalse
	return false
}
558234
func (f DoerFunc) Do(req *http.Request) (resp *http.Response, err error) {
	return f(req)
}
77994
func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
	resp, err := c.client.Do(req)
	if err != nil {
		return nil, err
	}

	defer func() {
		if rerr := resp.Body.Close(); err == nil {
			err = rerr
		}
	}()

	// Wrap our response.
	response := &Response{Response: resp}

	// Check for any errors that may have occurred.
	err = CheckResponse(resp)
	if err != nil {
		return response, err
	}

	if v != nil {
		if w, ok := v.(io.Writer); ok {
			_, err = io.Copy(w, resp.Body)
			if err != nil {
				return nil, err
			}
		} else {
			err = json.NewDecoder(resp.Body).Decode(&v)
			if err != nil {
				return nil, err
			}
		}

	}

	return response, err
}
342313
func Do(do DoFunc) Opt {
	return func(c *Client) Opt {
		old := c.do
		c.do = do
		return Do(old)
	}
}
285998
func (c *vstConnection) Do(ctx context.Context, req driver.Request) (driver.Response, error) {
	resp, err := c.do(ctx, req, c.transport)
	if err != nil {
		return nil, driver.WithStack(err)
	}
	return resp, nil
}
1303435
func (c *Client) do(req *http.Request) (io.ReadCloser, int64, error) {
	res, err := c.HTTPClient.Do(req)
	if err != nil {
		return nil, 0, err
	}

	if res.StatusCode < 400 {
		return res.Body, res.ContentLength, err
	}

	defer res.Body.Close()

	e := &Error{
		Status:     http.StatusText(res.StatusCode),
		StatusCode: res.StatusCode,
	}

	kind := res.Header.Get("Content-Type")

	if strings.Contains(kind, "text/plain") {
		if b, err := ioutil.ReadAll(res.Body); err == nil {
			e.Summary = string(b)
			return nil, 0, e
		}
		return nil, 0, err
	}

	if err := json.NewDecoder(res.Body).Decode(e); err != nil {
		return nil, 0, err
	}

	return nil, 0, e
}
752092
func (s *DeleteService) Do(ctx context.Context) (*DeleteResponse, error) {
	// Check pre-conditions
	if err := s.Validate(); err != nil {
		return nil, err
	}

	// Get URL for request
	path, params, err := s.buildURL()
	if err != nil {
		return nil, err
	}

	// Get HTTP response
	res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
		Method:       "DELETE",
		Path:         path,
		Params:       params,
		IgnoreErrors: []int{http.StatusNotFound},
	})
	if err != nil {
		return nil, err
	}

	// Return operation response
	ret := new(DeleteResponse)
	if err := s.client.decoder.Decode(res.Body, ret); err != nil {
		return nil, err
	}

	// If we have a 404, we return both a result and an error, just like ES does
	if res.StatusCode == http.StatusNotFound {
		return ret, &Error{Status: http.StatusNotFound}
	}

	return ret, nil
}
1039164
func (c *Client) Do(r *http.Request, v interface{}) error {
	var res *http.Response
	var err error
	if c.Client == nil {
		res, err = defaultHttpClient.Do(r)
	} else {
		res, err = c.Client.Do(r)
	}
	if err != nil {
		return err
	}
	defer res.Body.Close()
	if res.StatusCode >= 400 {
		if c.ErrorParser != nil {
			return c.ErrorParser(res)
		}
		return DefaultErrorParser(res)
	}

	resBody, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return err
	}
	if v == nil || res.StatusCode == http.StatusNoContent {
		return nil
	} else {
		return json.Unmarshal(resBody, v)
	}
}
1042605
func (c *Client) do(req *http.Request, remote string, via []*http.Request) (*http.Response, error) {
	return c.client.Do(req)
}
285257
func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
	if client == nil {
		client = http.DefaultClient
	}

	// Request cancelation changed in Go 1.5, see cancelreq.go and cancelreq_go14.go.
	cancel := canceler(client, req)

	type responseAndError struct {
		resp *http.Response
		err  error
	}
	result := make(chan responseAndError, 1)

	go func() {
		resp, err := client.Do(req)
		result <- responseAndError{resp, err}
	}()

	select {
	case <-ctx.Done():
		cancel()
		return nil, ctx.Err()
	case r := <-result:
		return r.resp, r.err
	}
}
172876
func (r *Request) Do() *Response {
	if r.err != nil {
		return &Response{
			err: r.err,
		}
	}

	req, err := r.request()
	if err != nil {
		return &Response{
			err: err,
		}
	}

	res, err := r.client.Do(req)
	if err != nil {
		return &Response{
			err: err,
		}
	}

	// return res, err
	return newResponse(res, err)
}
1132246
func (s *IndicesGetService) Do() (map[string]*IndicesGetResponse, error) {
	// Check pre-conditions
	if err := s.Validate(); err != nil {
		return nil, err
	}

	// Get URL for request
	path, params, err := s.buildURL()
	if err != nil {
		return nil, err
	}

	// Get HTTP response
	res, err := s.client.PerformRequest("GET", path, params, nil)
	if err != nil {
		return nil, err
	}

	// Return operation response
	var ret map[string]*IndicesGetResponse
	if err := json.Unmarshal(res.Body, &ret); err != nil {
		return nil, err
	}
	return ret, nil
}