Skip to content

Commit

Permalink
aws/dynamo/dynamo: add pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Oct 30, 2017
1 parent b41a295 commit 5adccc0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions aws/dynamo/dynamo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Package dynamo provides dynamodb utilities.
package dynamo

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

// Item is a map of attributes.
type Item map[string]*dynamodb.AttributeValue

// Marshal returns a new item from struct.
func Marshal(value interface{}) (Item, error) {
v, err := dynamodbattribute.MarshalMap(value)
if err != nil {
return nil, err
}

return Item(v), nil
}

// MustMarshal returns a new item from struct.
func MustMarshal(value interface{}) Item {
v, err := dynamodbattribute.MarshalMap(value)
if err != nil {
panic(err)
}

return Item(v)
}

// Unmarshal the item.
func Unmarshal(i Item, value interface{}) error {
return dynamodbattribute.UnmarshalMap(i, value)
}

0 comments on commit 5adccc0

Please sign in to comment.