-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.go
71 lines (58 loc) · 1.16 KB
/
message.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
package flow
import (
"context"
"time"
)
type Message struct {
ctx context.Context
headers map[string]string
data interface{}
extra map[string]interface{}
ts time.Time
}
func NewMessage(ctx context.Context) *Message {
return &Message{
ctx: ctx,
headers: make(map[string]string),
extra: make(map[string]interface{}),
ts: time.Now(),
}
}
func (m *Message) AddHeader(key string, val string) *Message {
m.headers[key] = val
return m
}
func (m *Message) GetHeader(key string) string {
res, ok := m.headers[key]
if ok {
return res
}
return ""
}
func (m *Message) SetExtra(extra map[string]interface{}) *Message {
m.extra = extra
return m
}
func (m *Message) SetData(data interface{}) *Message {
m.data = data
return m
}
func (m *Message) Extra() map[string]interface{} {
return m.extra
}
func (m *Message) Data() interface{} {
return m.data
}
func (m *Message) Headers() map[string]string {
return m.headers
}
func (m *Message) SetContext(ctx context.Context) *Message {
m.ctx = ctx
return m
}
func (m *Message) Context() context.Context {
return m.ctx
}
func (m *Message) Timestamp() int64 {
return m.ts.UnixMilli()
}