-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
57 lines (50 loc) · 1.45 KB
/
events.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package awsl
import (
"github.com/aws/aws-lambda-go/events"
)
// FromDynamoDBMap generates regular map out of events.DynamoDBAttributeValue map.
func FromDynamoDBMap(record map[string]events.DynamoDBAttributeValue) map[string]interface{} {
resultMap := make(map[string]interface{})
for key, rec := range record {
resultMap[key] = getDynamoDBAttributeValue(rec)
}
return resultMap
}
// getDynamoDBAttributeValue gets value from DynamoDBAttributeValue.
func getDynamoDBAttributeValue(record events.DynamoDBAttributeValue) interface{} {
var val interface{}
switch record.DataType() {
case events.DataTypeBinary:
val = record.Binary()
case events.DataTypeBinarySet:
val = record.BinarySet()
case events.DataTypeBoolean:
val = record.Boolean()
case events.DataTypeList:
list := record.List()
s := make([]interface{}, 0, len(record.List()))
for _, el := range list {
s = append(s, getDynamoDBAttributeValue(el))
}
val = s
case events.DataTypeMap:
mapData := record.Map()
// IMPORTANT: For DynamoDB only string can be a key in map.
m := make(map[string]interface{}, len(mapData))
for k, el := range mapData {
m[k] = getDynamoDBAttributeValue(el)
}
val = m
case events.DataTypeNull:
val = nil
case events.DataTypeNumber:
val = record.Number()
case events.DataTypeNumberSet:
val = record.NumberSet()
case events.DataTypeString:
val = record.String()
case events.DataTypeStringSet:
val = record.StringSet()
}
return val
}