// If v implements the io.Writer interface, the raw response body will be
// written to v, without attempting to first decode it.
//
// The provided ctx must be non-nil. If it is canceled or times out, ctx.Err()
// will be returned.
If v implements the io.Writer interface, the raw response body will be
written to v, without attempting to first decode it.

The provided ctx must be non-nil. If it is canceled or times out, ctx.Err()
will be returned.
// If v implements the io . Writer interface the raw response body will be // written to v without attempting to first decode it . // // The provided ctx must be non - nil . If it is canceled or times out ctx . Err () // will be returned .
func (c *Client) do(ctx context.Context, req *retryablehttp.Request, v interface{}) error {
	if err := c.limiter.Wait(ctx); err != nil {
		return err
	}
	req = req.WithContext(ctx)
	resp, err := c.http.Do(req)
	if err != nil {
		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
			return err
		}
	}
	defer resp.Body.Close()
	if err := checkResponseCode(resp); err != nil {
		return err
	}
	if v == nil {
		return nil
	}
	if w, ok := v.(io.Writer); ok {
		_, err = io.Copy(w, resp.Body)
		return err
	}
	dst := reflect.Indirect(reflect.ValueOf(v))
	if dst.Kind() != reflect.Struct {
		return fmt.Errorf("v must be a struct or an io.Writer")
	}
	items := dst.FieldByName("Items")
	pagination := dst.FieldByName("Pagination")
	if !items.IsValid() || !pagination.IsValid() {
		return jsonapi.UnmarshalPayload(resp.Body, v)
	}
	if items.Type().Kind() != reflect.Slice {
		return fmt.Errorf("v.Items must be a slice")
	}
	body := bytes.NewBuffer(nil)
	reader := io.TeeReader(resp.Body, body)
	raw, err := jsonapi.UnmarshalManyPayload(reader, items.Type().Elem())
	if err != nil {
		return err
	}
	sliceType := reflect.SliceOf(items.Type().Elem())
	result := reflect.MakeSlice(sliceType, 0, len(raw))
	for _, v := range raw {
		result = reflect.Append(result, reflect.ValueOf(v))
	}
	items.Set(result)
	p, err := parsePagination(body)
	if err != nil {
		return err
	}
	pagination.Set(reflect.ValueOf(p))
	return nil
}
func ( c * Client ) do ( ctx context . Context , req * retryablehttp . Request , v interface { } ) error { if err := c . limiter . Wait ( ctx ) ; err != nil { return err } req = req . WithContext ( ctx ) resp , err := c . http . Do ( req ) if err != nil { select { case <- ctx . Done ( ) : return ctx . Err ( ) default : return err } } defer resp . Body . Close ( ) if err := checkResponseCode ( resp ) ; err != nil { return err } if v == nil { return nil } if w , ok := v . ( io . Writer ) ; ok { _ , err = io . Copy ( w , resp . Body ) return err } dst := reflect . Indirect ( reflect . ValueOf ( v ) ) if dst . Kind ( ) != reflect . Struct { return fmt . Errorf ( " " ) } items := dst . FieldByName ( " " ) pagination := dst . FieldByName ( " " ) if ! items . IsValid ( ) || ! pagination . IsValid ( ) { return jsonapi . UnmarshalPayload ( resp . Body , v ) } if items . Type ( ) . Kind ( ) != reflect . Slice { return fmt . Errorf ( " " ) } body := bytes . NewBuffer ( nil ) reader := io . TeeReader ( resp . Body , body ) raw , err := jsonapi . UnmarshalManyPayload ( reader , items . Type ( ) . Elem ( ) ) if err != nil { return err } sliceType := reflect . SliceOf ( items . Type ( ) . Elem ( ) ) result := reflect . MakeSlice ( sliceType , 0 , len ( raw ) ) for _ , v := range raw { result = reflect . Append ( result , reflect . ValueOf ( v ) ) } items . Set ( result ) p , err := parsePagination ( body ) if err != nil { return err } pagination . Set ( reflect . ValueOf ( p ) ) return nil }
If v implements the io.Writer interface, the raw response body will be
written to v, without attempting to first decode it.
If v implements the io . Writer interface the raw response body will be written to v without attempting to first decode it .
// Wait will block until the limiter can obtain a new token // or returns an error if the given context is canceled. // Add the context to the request. // Execute the request and check the response. // If we got an error, and the context has been canceled, // the context's error is probably more useful. // Basic response checking. // Return here if decoding the response isn't needed. // If v implements io.Writer, write the raw response body. // Get the value of v so we can test if it's a struct. // Return an error if v is not a struct or an io.Writer. // Try to get the Items and Pagination struct fields. // Unmarshal a single value if v does not contain the // Items and Pagination struct fields. // Return an error if v.Items is not a slice. // Create a temporary buffer and copy all the read data into it. // Unmarshal as a list of values as v.Items is a slice. // Make a new slice to hold the results. // Add all of the results to the new slice. // Pointer-swap the result. // As we are getting a list of values, we need to decode // the pagination details out of the response body. // Pointer-swap the decoded pagination details.