Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 执行dynamoattribute.UnmarshalMap时,关系始终为零_Amazon Web Services_Go_Amazon Dynamodb_Unmarshalling - Fatal编程技术网

Amazon web services 执行dynamoattribute.UnmarshalMap时,关系始终为零

Amazon web services 执行dynamoattribute.UnmarshalMap时,关系始终为零,amazon-web-services,go,amazon-dynamodb,unmarshalling,Amazon Web Services,Go,Amazon Dynamodb,Unmarshalling,我有两个结构。取样和测试。”“样本”具有“测试”类型的关系。当我尝试执行“dynamoattribute.UnmarshalMap”时,关系总是为零。请您建议如何填充关系(本例中为“测试”)好吗 package main import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/aws/aws-sdk-go/s

我有两个结构。取样和测试。”“样本”具有“测试”类型的关系。当我尝试执行“dynamoattribute.UnmarshalMap”时,关系总是为零。请您建议如何填充关系(本例中为“测试”)好吗

package main

import (
    "fmt"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/service/dynamodb"
    "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)

type Sample struct {
    SampleId string `jsonapi:"attr,sampleId,omitempty" dynamodbav:"sample_id"`
    Test     *Test  `jsonapi:"relation,test"`
}

type Test struct {
    TestId string `jsonapi:"attr,testId,omitempty" dynamodbav:"test_id"`
}

func main() {
    var m map[string]*dynamodb.AttributeValue
    m = make(map[string]*dynamodb.AttributeValue)

    m["sample_id"] = &dynamodb.AttributeValue{
        S: aws.String("sample1"),
    }

    m["test_id"] = &dynamodb.AttributeValue{
        S: aws.String("test"),
    }

    sam := Sample{}

    err := dynamodbattribute.UnmarshalMap(m, &sam)
    if err != nil {
        fmt.Println(err)
    }

    fmt.Println(sam)
}
package main

import (
    "fmt"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/service/dynamodb"
    "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)

type Sample struct {
    SampleId string `jsonapi:"attr,sampleId,omitempty" dynamodbav:"sample_id"`
    Test     *Test  `jsonapi:"relation,test"`
}

type Test struct {
    TestId string `jsonapi:"primary,testId" dynamodbav:"test_id"`
}


func main() {
    var m map[string]*dynamodb.AttributeValue
    m = make(map[string]*dynamodb.AttributeValue)   

    m["sample_id"] = &dynamodb.AttributeValue{
        S: aws.String("sample1"),
    }

    var mTest map[string]*dynamodb.AttributeValue
    mTest = make(map[string]*dynamodb.AttributeValue)

    mTest["test_id"] = &dynamodb.AttributeValue{
        S: aws.String("test1"),
    }

    m["test"] = &dynamodb.AttributeValue{
        M: mTest,
    }

    sam := Sample{}

    err := dynamodbattribute.UnmarshalMap(m, &sam)
    if err != nil {
        fmt.Println(err)
    }

    fmt.Println(sam)
}