forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoding_aws.go
More file actions
30 lines (24 loc) · 755 Bytes
/
encoding_aws.go
File metadata and controls
30 lines (24 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package dynamo
import (
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)
type Coder interface {
Marshaler
Unmarshaler
}
type awsEncoder struct {
iface interface{}
}
func (w awsEncoder) MarshalDynamo() (*dynamodb.AttributeValue, error) {
return dynamodbattribute.Marshal(w.iface)
}
func (w awsEncoder) UnmarshalDynamo(av *dynamodb.AttributeValue) error {
return dynamodbattribute.Unmarshal(av, w.iface)
}
// AWSEncoding wraps an object, forcing it to use AWS's official dynamodbattribute package
// for encoding and decoding. This allows you to use the "dynamodbav" struct tags.
// When decoding, v must be a pointer.
func AWSEncoding(v interface{}) Coder {
return awsEncoder{v}
}