-
Notifications
You must be signed in to change notification settings - Fork 5
/
message.go
55 lines (44 loc) · 1.28 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
package message
import (
"encoding/json"
"github.com/rs/zerolog"
)
// Source is the type used to represent messages source
type Source string
func (s Source) String() string {
return string(s)
}
// Type is the type used to represent messages type
type Type string
func (t Type) String() string {
return string(t)
}
// DataVersion is the type used to represent messages data version
type DataVersion int
// SchemaVersion is the type used to represent mesages schema version
type SchemaVersion int
const (
// SchemaVersion3 is the only schema version available right now.
// All messages are produced with this as default.
SchemaVersion3 SchemaVersion = 3
)
// Message is the default event structure
type Message struct {
SchemaVersion SchemaVersion
ID string `json:"Id"`
Source Source
Type Type
CreatedAt string
DataVersion DataVersion
Data json.RawMessage
}
// MarshalZerologObject implements the zerolog marshaler so it can be logged using:
// log.With().EmbedObject(stakeholder).Msg("Some message")
func (m Message) MarshalZerologObject(e *zerolog.Event) {
e.
Str("msg_id", m.ID).
Str("msg_source", m.Source.String()).
Str("msg_created_at", m.CreatedAt).
Str("msg_type", m.Type.String()).
Int("msg_data_version", int(m.DataVersion))
}