forked from imjerrybao/apex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kinesis.go
49 lines (40 loc) · 1.3 KB
/
kinesis.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
// Package kinesis provides structs for working with AWS Kinesis records.
package kinesis
import (
"encoding/json"
"github.com/apex/apex"
)
// HandlerFunc unmarshals Kinesis events before passing control.
type HandlerFunc func(*Event, *apex.Context) error
// Handle implements apex.Handler.
func (h HandlerFunc) Handle(data json.RawMessage, ctx *apex.Context) (interface{}, error) {
var event Event
if err := json.Unmarshal(data, &event); err != nil {
return nil, err
}
return nil, h(&event, ctx)
}
// Event represents a Kinesis event with one or more records.
type Event struct {
Records []*Record `json:"Records"`
}
// Record represents a single Kinesis record.
type Record struct {
Kinesis struct {
SchemaVersion string `json:"kinesisSchemaVersion"`
PartitionKey string `json:"partitionKey"`
SequenceNumber string `json:"sequenceNumber"`
Data []byte `json:"data"`
}
EventSource string `json:"eventSource"`
EventVersion string `json:"eventVersion"`
EventID string `json:"eventID"`
EventName string `json:"eventName"`
InvokeIdentityARN string `json:"invokeIdentityArn"`
AWSRegion string `json:"awsRegion"`
EventSourceARN string `json:"eventSourceARN"`
}
// Data returns the payload.
func (r *Record) Data() []byte {
return r.Kinesis.Data
}