github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dis/v2/data/GetRecords.go (about)

     1  package data
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     6  )
     7  
     8  type GetRecordsOpts struct {
     9  	// Data cursor, which needs to be obtained through the API for obtaining data cursors.
    10  	// Value range: a string of 1 to 512 characters
    11  	// Note:
    12  	// The validity period of a data cursor is 5 minutes.
    13  	PartitionCursor string `q:"partition-cursor"`
    14  	// Maximum number of bytes that can be obtained for each request.
    15  	// Note:
    16  	// If the value is less than the size of a single record in the partition, the record cannot be obtained.
    17  	MaxFetchBytes *int `q:"max_fetch_bytes,omitempty"`
    18  }
    19  
    20  func GetRecords(client *golangsdk.ServiceClient, opts GetRecordsOpts) (*GetRecordsResponse, error) {
    21  	url, err := golangsdk.NewURLBuilder().WithEndpoints("records").WithQueryParams(&opts).Build()
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  
    26  	// GET /v2/{project_id}/records
    27  	raw, err := client.Get(client.ServiceURL(url.String()), nil, &golangsdk.RequestOpts{
    28  		MoreHeaders: map[string]string{"Content-Type": "application/json"},
    29  	})
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	var res GetRecordsResponse
    35  	err = extract.Into(raw.Body, &res)
    36  	return &res, err
    37  }
    38  
    39  type GetRecordsResponse struct {
    40  	Records []Record `json:"records,omitempty"`
    41  	// Next iterator.
    42  	// Note:
    43  	// The validity period of a data cursor is 5 minutes.
    44  	NextPartitionCursor string `json:"next_partition_cursor,omitempty"`
    45  }
    46  
    47  type Record struct {
    48  	// Partition key set when data is being uploaded.
    49  	// Note:
    50  	// If the partition_key parameter is passed when data is uploaded, this parameter will be returned when data is downloaded.
    51  	// If partition_id instead of partition_key is passed when data is uploaded, no partition_key is returned.
    52  	PartitionKey string `json:"partition_key,omitempty"`
    53  	// Sequence number of the data record.
    54  	SequenceNumber string `json:"sequence_number,omitempty"`
    55  	// Downloaded data.
    56  	// The downloaded data is the serialized binary data (Base64-encoded character string).
    57  	// For example, the data returned by the data download API is "ZGF0YQ==", which is "data" after Base64 decoding.
    58  	Data string `json:"data,omitempty"`
    59  	// Timestamp when the record is written to DIS.
    60  	CreatedAt *int64 `json:"timestamp,omitempty"`
    61  	// Timestamp data type.
    62  	// CreateTime: creation time.
    63  	// Default: CreateTime
    64  	TimestampType string `json:"timestamp_type,omitempty"`
    65  }