a8m / a8m/documentdb

DocumentIterator usage can corrupt data if you forget to zero/nil your buffer

オープン
#39 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Go
スター
31
フォーク
26
PR マージ指標
30日以内にマージされた PR はありません

説明

Since it is a slice reference, any nested structs or arrays in your data will be sparsely overwritten during iteration and can still include old data from past iteration if you follow the docs:
```func main() {
// ...
var docs []Document

iterator := documentdb.NewIterator(
client, documentdb.NewDocumentIterator("coll_self_link", nil, &docs, documentdb.PartitionKey("1"), documentdb.Limit(1)),
)

for iterator.Next() {
if err := iterator.Error(); err != nil {
log.Fatal(err)
}
fmt.Println(len(docs))
}

// ...
}```

Instead, nil the buffer like this:
```
func main() {
// ...
var docs []Document

iterator := documentdb.NewIterator(
client, documentdb.NewDocumentIterator("coll_self_link", nil, &docs, documentdb.PartitionKey("1"), documentdb.Limit(1)),
)

for iterator.Next() {
if err := iterator.Error(); err != nil {
log.Fatal(err)
}
fmt.Println(len(docs))
docs = nil // zero your buffer to avoid corrupt data!
}

// ...
}```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。