示例#1
0
// Persist persists its state
func (u *User) Persist() error {
	items := map[string]*dynamodb.AttributeValue{}
	items["ID"] = aws.DynamoAttributeS(u.ID)
	items["Name"] = aws.DynamoAttributeS(u.Name)
	_, err := aws.DynamoPutItem(userTable, items)
	if err != nil {
		logs.Error.Printf("User#Persist. Items: %v, Error: %v", items, err)
	}
	return err
}
示例#2
0
// GetUser retrives a specified user from DynamoDB
//  @param  id string
//  @return user models.User
func GetUser(id string) (user *User, found bool) {
	record, err := aws.DynamoRecord(userTable, map[string]*dynamodb.AttributeValue{
		"ID": aws.DynamoAttributeS(id),
	})
	if (err != nil) || len(record) == 0 {
		return nil, false
	}
	return toUser(record), true
}