Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // GetItem finds a returns a single item from a dynamodb table.
- // It returns an element and an error if any.
- // If no element is found, will return nil without an error
- func GetItem(id string, dest interface{}) error {
- tableName := "table-name"
- // create get operation information
- item := &dynamodb.GetItemInput{
- TableName: aws.String(tableName),
- Key: map[string]*dynamodb.AttributeValue{
- "ID": {S: aws.String(id)},
- },
- }
- // execute GetItem operation
- result, err := DynamoDB().GetItem(item)
- if err != nil {
- return err
- }
- return dynamodbattribute.UnmarshalMap(result.Item, &dest)
- }
- type Product struct {
- ID string `json:"id"`
- Name string `json:"name"`
- }
- func main() err {
- p := Product{}
- if err := GetItem("p-id", &p); err != nil {
- return err
- }
- return nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement