sendgridlabs/go-kinesis — pull request #16 by harlow (2014-12-08 00:41:22+00:00)
Title: Add PutRecords functionality

## Pull Request Description

AWS Kinesis has released a batch PUT API for bulk additions to a stream.

* Add PutRecords functionality to Kinesis
* Alphabetically order struct attributes
* Add line breaks for long parameter lists

Fixes https://github.com/sendgridlabs/go-kinesis/issues/15

## Encoding help needed

Hi @le0pard I was wondering if you could help me debug the encoding issue I'm running into.

Putting batch data to Kinesis seems to be working as expected:

```go
args = kinesis.NewArgs()
args.Add("StreamName", streamName)

for i := 0; i < 10; i++ {
args.AddRecord(
[]byte(fmt.Sprintf("Hello AWS Kinesis %d", i)),
fmt.Sprintf("partitionKey-%d", i),
)
}

resp4, err := ksis.PutRecords(args)

if err != nil {
fmt.Printf("PutRecords err: %v\n", err)
} else {
fmt.Printf("PutRecords: %v\n", resp4)
}
```

Here is the generated JSON payload:

```json
{"Records":[{"Data":"SGVsbG8gQVdTIEtpbmVzaXMgMA==","PartitionKey":"partitionKey-0"},{"Data":"SGVsbG8gQVdTIEtpbmVzaXMgMQ==","PartitionKey":"partitionKey-1"},{"Data":"SGVsbG8gQVdTIEtpbmVzaXMgMg==","PartitionKey":"partitionKey-2"},{"Data":"SGVsbG8gQVdTIEtpbmVzaXMgMw==","PartitionKey":"partitionKey-3"},{"Data":"SGVsbG8gQVdTIEtpbmVzaXMgNA==","PartitionKey":"partitionKey-4"},{"Data":"SGVsbG8gQVdTIEtpbmVzaXMgNQ==","PartitionKey":"partitionKey-5"},{"Data":"SGVsbG8gQVdTIEtpbmVzaXMgNg==","PartitionKey":"partitionKey-6"},{"Data":"SGVsbG8gQVdTIEtpbmVzaXMgNw==","PartitionKey":"partitionKey-7"},{"Data":"SGVsbG8gQVdTIEtpbmVzaXMgOA==","PartitionKey":"partitionKey-8"},{"Data":"SGVsbG8gQVdTIEtpbmVzaXMgOQ==","PartitionKey":"partitionKey-9"}],"StreamName":"test"}
```

The Base64 encoded `Data` seems valid (https://www.base64decode.org)

```
SGVsbG8gQVdTIEtpbmVzaXMgMQ==
- converts to -
Hello AWS Kinesis 1
```

However, the example program then gives me the following error when it reads from Kinesis:

```
GetRecords Data BEGIN
GetRecords Data: �e, err: illegal base64 data at input byte 5
GetRecords Data: �e, err: illegal base64 data at input byte 5
GetRecords Data: �e, err: illegal base64 data at input byte 5
GetRecords Data: �e, err: illegal base64 data at input byte 5
GetRecords Data END
```

Any ideas?