amazon-web-services - 带有限制的AWS dynamoDb分页

标签 amazon-web-services go amazon-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, 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:

  • 如果结果包含LastEvaluatedKey元素且非null,请继续执行步骤2。
  • 如果结果中没有LastEvaluatedKey,则不再有要检索的项目。
  • 关于amazon-web-services - 带有限制的AWS dynamoDb分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63616392/

    相关文章:

    arrays - 如何在 Go 中跨多个数组检查变量

    python - 如何从AWS DynamoDB python异常中提取异常消息?

    amazon-web-services - lambda@edge 超时和 s3 图像处理

    amazon-web-services - AWS Lambda 通过 zip 文件上传不起作用

    compiler-construction - 在 Windows 64 位中编译 Go 的问题

    amazon-web-services - AWS 上用于 SNS 通知的多区域架构

    java - 在 Java 中查询具有动态属性的 Dynamo 表

    php - 在 Linux 服务器上创建 S3Client 失败

    amazon-web-services - 无法提取 secret 或注册表身份验证 : pull command failed: : signal: killed

    go - 滑行更新清空 glide.lock