a8m / a8m/documentdb

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

未關閉
#39 0 則留言 0 個 reaction 已指派 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 摘要。