a8m / a8m/documentdb

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

Đang mở
#39 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Go
Star
31
Fork
26
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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!
}

// ...
}```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.