如何解决带有限制的AWS dynamoDB分页
我正在尝试对dynamoDb中创建的表中的条目进行分页 无论如何,是否要检查表项是否已超出。
例如,如果我打电话从表中获取项目,则会出现以下错误
PANIC: runtime error: invalid memory address or nil pointer dereference
goroutine 51 [running]:
github.com/urfave/negroni.(*Recovery).ServeHTTP.func1(0xdfae028,0xc000186028,0xc0002162d0,0xc000154200)
/Users/hammadali/go/pkg/mod/github.com/urfave/negroni@v1.0.0/recovery.go:159 +0xcb
panic(0x498ea20,0x51f4410)
/usr/local/Cellar/go/1.14.5/libexec/src/runtime/panic.go:969 +0x166
github.com/prohousing-as/ph-supplier-service/application.(*SupplierService).GetAllSuppliers(0xc0002cc300,0xc00002a270,0x24,0xbb8,0xc0004403e0,0x0,0x0)
/Users/hammadali/source/ph-supplier-service/application/supplier_service.go:41 +0x330
github.com/prohousing-as/ph-supplier-service/ui.(*SupplierController).GetAllSupplier(0xc000526ed0,0xdfae028,0xc0003be300)
/Users/hammadali/source/ph-supplier-service/ui/supplier_controller.go:40 +0x139
net/http.HandlerFunc.ServeHTTP(0xc000527170,0xc0003be300)
/usr/local/Cellar/go/1.14.5/libexec/src/net/http/server.go:2041 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0002e40c0,0xc0003be100)
/Users/hammadali/go/pkg/mod/github.com/gorilla/mux@v1.7.4/mux.go:210 +0xe2
获取所有项目的功能
// fetches the items from dynamoDb and stores it in res
res,err := s.SupplierRepo.GetAllSupplier(uuid,limit)
if err != nil {
fmt.Println("from application: ",err)
return nil,err
}
item := &domain.SupplierTableItems{}
all := &domain.AllSupplierItems{}
// Looping over the result and appending it on the list
for _,i := range res.Items {
err = dynamodbattribute.UnmarshalMap(i,item)
all.Collection = append(all.Collection,*item)
if err != nil {
fmt.Println(err)
}
}
// storing lastEvaluatedKey for pagination
all.LastEvaluatedKey = *res.LastEvaluatedKey["uuid"].S
return all,nil
无论如何,是否需要检查获取项目的调用是否已超出表条目,并仅提供剩余的条目数即可。
解决方法
您的错误与DynamoDB的分页无关,您只是在尝试访问/Users/hammadali/source/ph-supplier-service/application/supplier_service.go:41
周围某处不存在的内容
否则将回答您的问题:是的,DynamoDB会告诉您何时完成分页。 From the docs:
- 如果结果包含LastEvaluatedKey元素且非null,请继续执行步骤2。
- 如果结果中没有LastEvaluatedKey,则不再有要检索的项目。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。