Skip to content

Instantly share code, notes, and snippets.

@girishramnani
Last active October 12, 2019 16:10
Show Gist options
  • Save girishramnani/77828897be582086fe6feb774e173a8f to your computer and use it in GitHub Desktop.
Save girishramnani/77828897be582086fe6feb774e173a8f to your computer and use it in GitHub Desktop.
package main
import (
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
"fmt"
)
type Tpl struct {
Year int
Title string
Plot string
Rating float64
}
func main() {
result := dynamodb.QueryOutput{}
sample, _ := dynamodbattribute.MarshalMap(Tpl{
Year: 2019,
Title: "Hello World",
Plot: "Something awesome",
})
// mocking the output as we dont want to connect to aws
result.Items = []map[string]*dynamodb.AttributeValue{
sample,
}
// actual code starts here, above code is for mocking
// this has to be the list of struct you defined
var c []Tpl
for _, item := range result.Items {
iterTpl := Tpl{}
dynamodbattribute.UnmarshalMap(item, &iterTpl)
c = append(c, iterTpl)
}
fmt.Printf("Tpl list: %+v\n", c)
// snippet-end:[dynamodb.go.read_item.unmarshall]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment