// Do is a cancelable function to interface with Influx Enterprise's Meta API
508220
func (m *MetaClient) Do(ctx context.Context, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error) {
	type result struct {
		Response *http.Response
		Err      error
	}

	resps := make(chan (result))
	go func() {
		resp, err := m.client.Do(m.URL, path, method, authorizer, params, body)
		resps <- result{resp, err}
	}()

	select {
	case resp := <-resps:
		return resp.Response, resp.Err
	case <-ctx.Done():
		return nil, chronograf.ErrUpstreamTimeout
	}
}
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
}
323699
func (l *Client) Do(r *http.Request, response, data interface{}) error {
	// make the request

	res, err := l.client.Do(r)
	if err != nil {
		return err
	}
	defer res.Body.Close()

	// get the response
	b, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return err
	}

	// if we have some struct to unmarshal body into, do that and return
	if response != nil {
		err = buildRespJSON(b, response, data)
		if err != nil {
			return err
		}
		switch rt := response.(type) {
		case *ApiResp:
			// if we have an invalid response code error out
			if res.StatusCode >= 301 {
				return fmt.Errorf(rt.Message)
			}
		}
	}

	// if we have an invalid response code error out
	if res.StatusCode >= 301 {
		return fmt.Errorf("Received non-successful response: %d", res.StatusCode)
	}

	return nil
}
1337621
func (c *Client) do(req *http.Request, v interface{}) (*http.Response, error) {
	resp, err := c.client.Do(req)
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	if status := resp.StatusCode; status < 200 || status > 299 {
		return resp, RegistryError{Code: status, method: req.Method, url: req.URL}
	}

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

	return resp, err
}
619495
func (f PolicyFunc) Do(ctx context.Context, request Request) (Response, error) {
	return f(ctx, request)
}
1000198
func (c *ClusterClient) Do(args ...interface{}) *Cmd {
	cmd := NewCmd(args...)
	c.Process(cmd)
	return cmd
}
684678
func (c *traceClient) Do(r *http.Request) (*http.Response, error) {
	InjectTrace(r)
	return c.Client.Do(r)
}
231946
func (s *CountService) Do(ctx context.Context) (int64, error) {
	// Check pre-conditions
	if err := s.Validate(); err != nil {
		return 0, err
	}

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

	// Setup HTTP request body
	var body interface{}
	if s.query != nil {
		src, err := s.query.Source()
		if err != nil {
			return 0, err
		}
		query := make(map[string]interface{})
		query["query"] = src
		body = query
	} else if s.bodyJson != nil {
		body = s.bodyJson
	} else if s.bodyString != "" {
		body = s.bodyString
	}

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

	// Return result
	ret := new(CountResponse)
	if err := s.client.decoder.Decode(res.Body, ret); err != nil {
		return 0, err
	}
	if ret != nil {
		return ret.Count, nil
	}

	return int64(0), nil
}
1046954
func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error) {
	// TODO: setting the request ID should be done via client middleware. For now only set it if the
	// caller provided one in the ctx.
	if ctxreqid := ContextRequestID(ctx); ctxreqid != "" {
		req.Header.Set("X-Request-Id", ctxreqid)
	}
	if c.UserAgent != "" {
		req.Header.Set("User-Agent", c.UserAgent)
	}
	startedAt := time.Now()
	ctx, id := ContextWithRequestID(ctx)
	goa.LogInfo(ctx, "started", "id", id, req.Method, req.URL.String())
	if c.Dump {
		c.dumpRequest(ctx, req)
	}
	resp, err := c.Doer.Do(ctx, req)
	if err != nil {
		goa.LogError(ctx, "failed", "err", err)
		return nil, err
	}
	goa.LogInfo(ctx, "completed", "id", id, "status", resp.StatusCode, "time", time.Since(startedAt).String())
	if c.Dump {
		c.dumpResponse(ctx, resp)
	}
	return resp, err
}
1148360
func (c *Client) Do(f func()) {
	c.volatile.RLock()
	defer c.volatile.RUnlock()

	f()
}
777888
func (rt *registryRoundTripper) Do(ctx context.Context, r *http.Request,
	v interface{}) (*http.Response, error) {

	ctx, cancelFunc := context.WithTimeout(ctx, 60*time.Second)
	r = r.WithContext(ctx)
	defer cancelFunc()

	resp, err := rt.DefaultRequestDoer.Do(ctx, r, v)
	if err != nil {
		if ctx.Err() == context.DeadlineExceeded {
			err = &apitypes.Error{
				Type: apitypes.RequestTimeoutError,
				Err:  []string{"Request timed out"},
			}
		}

		return nil, err
	}

	return resp, nil
}
1191101
func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error) {

	if len(c.AuthToken) > 0 {
		// only add this header if not already set (e.g. for authClient)
		if len(req.Header.Get(common.AuthHeaderKey)) == 0 {
			common.AddServiceTokenHeader(req, c.AuthToken)
		}
	}
	if len(c.DownloadServiceToken) > 0 {
		// only add this header if not already set
		if len(req.Header.Get(common.DownloadServiceHeaderKey)) == 0 {
			common.AddDownloadServiceTokenHeader(req, c.DownloadServiceToken)
		}
	}
	if common.IsUserPresent(ctx) {
		// only add this header if not already set
		if len(req.Header.Get(common.UserHeaderKey)) == 0 {
			common.AddUserHeader(req, common.User(ctx))
		}
	}
	if common.IsFlorenceIdentityPresent(ctx) {
		common.SetFlorenceHeader(ctx, req)
	}

	// get any existing correlation-id (might be "id1,id2"), append a new one, add to headers
	upstreamCorrelationIds := common.GetRequestId(ctx)
	addedIdLen := 20
	if upstreamCorrelationIds != "" {
		// get length of (first of) IDs (e.g. "id1" is 3), new ID will be half that size
		addedIdLen = len(upstreamCorrelationIds) / 2
		if commaPosition := strings.Index(upstreamCorrelationIds, ","); commaPosition > 1 {
			addedIdLen = commaPosition / 2
		}
		upstreamCorrelationIds += ","
	}
	common.AddRequestIdHeader(req, upstreamCorrelationIds+common.NewRequestID(addedIdLen))

	doer := func(args ...interface{}) (*http.Response, error) {
		req := args[2].(*http.Request)
		if req.ContentLength > 0 {
			var err error
			req.Body, err = req.GetBody()
			if err != nil {
				return nil, err
			}
		}
		return ctxhttp.Do(args[0].(context.Context), args[1].(*http.Client), req)
	}

	resp, err := doer(ctx, c.HTTPClient, req)
	if err != nil {
		if c.ExponentialBackoff {
			return c.backoff(doer, err, ctx, c.HTTPClient, req)
		}
		return nil, err
	}

	if c.ExponentialBackoff {
		if resp.StatusCode >= http.StatusInternalServerError {
			return c.backoff(doer, err, ctx, c.HTTPClient, req, errors.New("Bad server status"))
		}

		if resp.StatusCode == http.StatusConflict {
			return c.backoff(doer, err, ctx, c.HTTPClient, req, errors.New("Conflict - request could not be completed due to a conflict with the current state of the target resource"))
		}
	}

	return resp, err
}
977142
func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error) {
	var resp *http.Response
	var err error

	if c.Debug {
		fmt.Println(req.URL.String())
	}

	err = backoff.Retry(func() error {
		resp, err = c.client.Do(req)
		if err != nil {
			return err
		}
		if c := resp.StatusCode; c == 500 || c >= 502 && c <= 599 {
			// Avoid retry on 501: Not Implemented
			err = &status5xx{}
		}
		return err
	}, c.b)
	c.b.Reset()

	if err != nil {
		if _, ok := err.(*status5xx); !ok {
			return nil, err
		}
	}

	if c.Debug {
		dump, err := httputil.DumpResponse(resp, true)
		if err == nil {
			fmt.Println(string(dump))
		}
	}

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

	err = checkResponse(resp)
	if err != nil {
		return resp, err
	}

	if v != nil {
		//bb, _ := ioutil.ReadAll(resp.Body)
		//fmt.Println(string(bb))
		//
		//err := json.Unmarshal(bb, v)
		//if err != nil {
		//	return nil, err
		//}

		err = json.NewDecoder(resp.Body).Decode(v)
		if err != nil {
			return nil, err
		}
	}
	return resp, err
}
365447
func (s *PingService) Do(ctx context.Context) (*PingResult, int, error) {
	s.client.mu.RLock()
	basicAuth := s.client.basicAuth
	basicAuthUsername := s.client.basicAuthUsername
	basicAuthPassword := s.client.basicAuthPassword
	s.client.mu.RUnlock()

	url_ := s.url + "/"

	params := make(url.Values)
	if s.timeout != "" {
		params.Set("timeout", s.timeout)
	}
	if s.pretty {
		params.Set("pretty", "true")
	}
	if len(params) > 0 {
		url_ += "?" + params.Encode()
	}

	var method string
	if s.httpHeadOnly {
		method = "HEAD"
	} else {
		method = "GET"
	}

	// Notice: This service must NOT use PerformRequest!
	req, err := NewRequest(method, url_)
	if err != nil {
		return nil, 0, err
	}

	if basicAuth {
		req.SetBasicAuth(basicAuthUsername, basicAuthPassword)
	}

	res, err := s.client.c.Do((*http.Request)(req).WithContext(ctx))
	if err != nil {
		return nil, 0, err
	}
	defer res.Body.Close()

	var ret *PingResult
	if !s.httpHeadOnly {
		ret = new(PingResult)
		if err := json.NewDecoder(res.Body).Decode(ret); err != nil {
			return nil, res.StatusCode, err
		}
	}

	return ret, res.StatusCode, nil
}
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)
		}
	})
}
422773
func (c *ChannelsUnarchiveCall) Do(ctx context.Context) error {
	const endpoint = "channels.unarchive"
	v, err := c.Values()
	if err != nil {
		return err
	}
	var res struct {
		objects.GenericResponse
	}
	if err := c.service.client.postForm(ctx, endpoint, v, &res); err != nil {
		return errors.Wrap(err, `failed to post to channels.unarchive`)
	}
	if !res.OK {
		return errors.New(res.Error.String())
	}

	return nil
}
705197
func Do(req *http.Request) (resp *http.Response, err error) {
	c := New()
	return c.Do(req)
}