This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathevent.go
153 lines (123 loc) · 3.26 KB
/
event.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
Copyright 2017 The Nuclio Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package nuclio
import (
"errors"
"time"
)
var ErrUnsupported = errors.New("Event does not support this interface")
type SourceInfoProvider interface {
// get the class of source (sync, async, etc)
GetClass() string
// get specific kind of source (http, rabbit mq, etc)
GetKind() string
}
//
// An event
//
type Event interface {
GetVersion() int
GetID() ID
SetID(id ID)
SetSourceProvider(sourceInfoProvider SourceInfoProvider)
GetSource() SourceInfoProvider
GetContentType() string
GetBody() []byte
GetSize() int
GetHeader(key string) interface{}
GetHeaderByteSlice(key string) []byte
GetHeaderString(key string) string
GetHeaders() map[string]interface{}
GetField(key string) interface{}
GetFieldByteSlice(key string) []byte
GetFieldString(key string) string
GetFieldInt(key string) (int, error)
GetFields() map[string]interface{}
GetTimestamp() time.Time
GetPath() string
GetURL() string
GetMethod() string
}
//
// Abstract implementation of event
//
type AbstractEvent struct {
sourceInfoProvider SourceInfoProvider
id ID
emptyByteArray []byte
emptyHeaders map[string]interface{}
emptyTime time.Time
}
func (ae *AbstractEvent) GetVersion() int {
return 0
}
func (ae *AbstractEvent) SetSourceProvider(sourceInfoProvider SourceInfoProvider) {
ae.sourceInfoProvider = sourceInfoProvider
}
func (ae *AbstractEvent) GetSource() SourceInfoProvider {
return ae.sourceInfoProvider
}
func (ae *AbstractEvent) GetID() ID {
return ae.id
}
func (ae *AbstractEvent) SetID(id ID) {
ae.id = id
}
func (ae *AbstractEvent) GetContentType() string {
return ""
}
func (ae *AbstractEvent) GetBody() []byte {
return ae.emptyByteArray
}
func (ae *AbstractEvent) GetSize() int {
return 0
}
func (ae *AbstractEvent) GetHeader(key string) interface{} {
return nil
}
func (ae *AbstractEvent) GetHeaderByteSlice(key string) []byte {
return ae.emptyByteArray
}
func (ae *AbstractEvent) GetHeaderString(key string) string {
return string(ae.GetHeaderByteSlice(key))
}
func (ae *AbstractEvent) GetHeaders() map[string]interface{} {
return ae.emptyHeaders
}
func (ae *AbstractEvent) GetTimestamp() time.Time {
return ae.emptyTime
}
func (ae *AbstractEvent) GetPath() string {
return ""
}
func (ae *AbstractEvent) GetURL() string {
return ""
}
func (ae *AbstractEvent) GetMethod() string {
return ""
}
func (ae *AbstractEvent) GetField(key string) interface{} {
return nil
}
func (ae *AbstractEvent) GetFieldByteSlice(key string) []byte {
return nil
}
func (ae *AbstractEvent) GetFieldString(key string) string {
return ""
}
func (ae *AbstractEvent) GetFieldInt(key string) (int, error) {
return 0, ErrUnsupported
}
func (ae *AbstractEvent) GetFields() map[string]interface{} {
return nil
}