我正在尝试从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, 0xc000186028, 0xc0003be300)
/Users/hammadali/source/ph-supplier-service/ui/supplier_controller.go:40 +0x139
net/http.HandlerFunc.ServeHTTP(0xc000527170, 0xdfae028, 0xc000186028, 0xc0003be300)
/usr/local/Cellar/go/1.14.5/libexec/src/net/http/server.go:2041 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0002e40c0, 0xdfae028, 0xc000186028, 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:
关于amazon-web-services - 带有限制的AWS dynamoDb分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63616392/