-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
100 lines (80 loc) · 2.03 KB
/
structs.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
package pubSubWorkflow
import (
"encoding/json"
amqpWrapper "github.com/markshapiro/go-pubsub-workflow/amqp"
"github.com/go-redis/redis"
)
type message struct {
CallId string
MessageId int64
SessionId int64
Subject string
Args Args
}
func (m message) MarshalBinary() ([]byte, error) {
return json.Marshal(m)
}
func (m *message) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, m)
}
type Args struct {
Data string `json:"Data,omitempty"`
Events []Event `json:"Events,omitempty"`
}
const (
Publish = "publish"
EmitEvent = "emitEvent"
)
type Action struct {
Type string
QueueId string `json:"QueueId,omitempty"`
Event string `json:"Event,omitempty"`
Subject string `json:"Subject,omitempty"`
Data string `json:"Data,omitempty"`
}
type PublishTrigger struct {
Events []string
PublishTriggerId int64
QueueId string `json:"QueueId,omitempty"`
Subject string
Data string `json:"Data,omitempty"`
}
func (m PublishTrigger) MarshalBinary() ([]byte, error) {
return json.Marshal(m)
}
func (m *PublishTrigger) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, m)
}
type Event struct {
Name string
Data string `json:"Data,omitempty"`
}
type storedResult struct {
Actions []Action `json:"Actions,omitempty"`
PublishTriggers []PublishTrigger `json:"PublishTriggers,omitempty"`
}
func (m storedResult) MarshalBinary() ([]byte, error) {
return json.Marshal(m)
}
func (m *storedResult) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, m)
}
type handlerInfo struct {
subject string
handlerFn handlerFunc
}
type PubSubWorkflow interface {
Connect(string, string) error
StartListening() error
Subscribe(string, handlerFunc) error
Publish(string, string, ...string) error
Reset() error
Close() error
}
type pubSubWorkflow struct {
queueId string
amqpConn *amqpWrapper.AMQPConn
redisConn *redis.Client
handlers *[]handlerInfo
}
type handlerFunc func(string, []Event) ([]Action, []PublishTrigger, error)