github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dis/v2/data/PutRecords.go (about) 1 package data 2 3 import ( 4 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/build" 6 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 7 ) 8 9 type PutRecordsOpts struct { 10 // Name of the stream. 11 // Maximum: 64 12 StreamName string `json:"stream_name" required:"true"` 13 // Unique ID of the stream. 14 // If no stream is found by stream_name and stream_id is not empty, stream_id is used to search for the stream. 15 // Note: 16 // This parameter is mandatory when data is uploaded to the authorized stream. 17 StreamId string `json:"stream_id,omitempty"` 18 // List of records to be uploaded. 19 Records []PutRecordsRequestEntry `json:"records" required:"true"` 20 } 21 22 func PutRecords(client *golangsdk.ServiceClient, opts PutRecordsOpts) (*PutRecordsResponse, error) { 23 b, err := build.RequestBody(opts, "") 24 if err != nil { 25 return nil, err 26 } 27 28 // POST /v2/{project_id}/records 29 raw, err := client.Post(client.ServiceURL("records"), b, nil, &golangsdk.RequestOpts{ 30 OkCodes: []int{200}, 31 }) 32 if err != nil { 33 return nil, err 34 } 35 36 var res PutRecordsResponse 37 err = extract.Into(raw.Body, &res) 38 return &res, err 39 } 40 41 type PutRecordsRequestEntry struct { 42 // Data to be uploaded. The uploaded data is the serialized binary data (character string encoded using Base64). 43 // For example, if the character string data needs to be uploaded, the character string after Base64 encoding is ZGF0YQ==. 44 Data string `json:"data"` 45 // Hash value of the data to be written to the partition. The hash value overwrites the hash value of partition_key. Value range: 0–long.max 46 ExplicitHashKey string `json:"explicit_hash_key,omitempty"` 47 // Partition ID of the stream. The value can be in either of the following formats: 48 // shardId-0000000000 49 // 0 50 // For example, if a stream has three partitions, the partition identifiers are 0, 1, and 2, or shardId-0000000000, shardId-0000000001, and shardId-0000000002, respectively. 51 PartitionId string `json:"partition_id,omitempty"` 52 // Partition to which data is written to. Note: 53 // If the partition_id parameter is transferred, the partition_id parameter is used preferentially. 54 // If partition_id is not transferred, partition_key is used. 55 PartitionKey string `json:"partition_key,omitempty"` 56 } 57 58 type PutRecordsResponse struct { 59 // Number of data records that fail to be uploaded. 60 FailedRecordCount *int `json:"failed_record_count,omitempty"` 61 62 Records []PutRecordsResultEntry `json:"records,omitempty"` 63 } 64 65 type PutRecordsResultEntry struct { 66 // ID of the partition to which data is uploaded. 67 PartitionId string `json:"partition_id,omitempty"` 68 // Sequence number of the data to be uploaded. 69 // A sequence number is a unique identifier for each record. 70 // DIS automatically allocates a sequence number the data producer calls the PutRecords operation to add data to the DIS stream. 71 // Sequence number of the same partition key usually changes with time. A longer interval between PutRecords requests results in a larger sequence number. 72 SequenceNumber string `json:"sequence_number,omitempty"` 73 // Error code. 74 ErrorCode string `json:"error_code,omitempty"` 75 // Error message. 76 ErrorMessage string `json:"error_message,omitempty"` 77 }