-
Notifications
You must be signed in to change notification settings - Fork 218
/
event_interface.go
102 lines (88 loc) · 3.24 KB
/
event_interface.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Copyright 2021 The CloudEvents Authors
SPDX-License-Identifier: Apache-2.0
*/
package event
import (
"time"
)
// EventReader is the interface for reading through an event from attributes.
type EventReader interface {
// SpecVersion returns event.Context.GetSpecVersion().
SpecVersion() string
// Type returns event.Context.GetType().
Type() string
// Source returns event.Context.GetSource().
Source() string
// Subject returns event.Context.GetSubject().
Subject() string
// ID returns event.Context.GetID().
ID() string
// Time returns event.Context.GetTime().
Time() time.Time
// DataSchema returns event.Context.GetDataSchema().
DataSchema() string
// DataContentType returns event.Context.GetDataContentType().
DataContentType() string
// DataMediaType returns event.Context.GetDataMediaType().
DataMediaType() string
// DeprecatedDataContentEncoding returns event.Context.DeprecatedGetDataContentEncoding().
DeprecatedDataContentEncoding() string
// Extension Attributes
// Extensions returns the event.Context.GetExtensions().
// Extensions use the CloudEvents type system, details in package cloudevents/types.
Extensions() map[string]interface{}
// ExtensionAs returns event.Context.ExtensionAs(name, obj).
//
// DEPRECATED: Access extensions directly via the e.Extensions() map.
// Use functions in the types package to convert extension values.
// For example replace this:
//
// var i int
// err := e.ExtensionAs("foo", &i)
//
// With this:
//
// i, err := types.ToInteger(e.Extensions["foo"])
//
ExtensionAs(string, interface{}) error
// Data Attribute
// Data returns the raw data buffer
// If the event was encoded with base64 encoding, Data returns the already decoded
// byte array
Data() []byte
// DataAs attempts to populate the provided data object with the event payload.
DataAs(interface{}) error
}
// EventWriter is the interface for writing through an event onto attributes.
// If an error is thrown by a sub-component, EventWriter caches the error
// internally and exposes errors with a call to event.Validate().
type EventWriter interface {
// Context Attributes
// SetSpecVersion performs event.Context.SetSpecVersion.
SetSpecVersion(string)
// SetType performs event.Context.SetType.
SetType(string)
// SetSource performs event.Context.SetSource.
SetSource(string)
// SetSubject( performs event.Context.SetSubject.
SetSubject(string)
// SetID performs event.Context.SetID.
SetID(string)
// SetTime performs event.Context.SetTime.
SetTime(time.Time)
// SetDataSchema performs event.Context.SetDataSchema.
SetDataSchema(string)
// SetDataContentType performs event.Context.SetDataContentType.
SetDataContentType(string)
// DeprecatedSetDataContentEncoding performs event.Context.DeprecatedSetDataContentEncoding.
SetDataContentEncoding(string)
// Extension Attributes
// SetExtension performs event.Context.SetExtension.
SetExtension(string, interface{})
// SetData encodes the given payload with the given content type.
// If the provided payload is a byte array, when marshalled to json it will be encoded as base64.
// If the provided payload is different from byte array, datacodec.Encode is invoked to attempt a
// marshalling to byte array.
SetData(string, interface{}) error
}