-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_gen.go
93 lines (82 loc) · 2.11 KB
/
event_gen.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
// Code generated ; DO NOT EDIT
package appevent
import (
"context"
"github.com/hori-ryota/go-genappevent/_example/application"
"github.com/hori-ryota/go-genappevent/_example/domain"
"github.com/hori-ryota/go-genappevent/_example/external/appevent"
)
type EventPublisher struct {
ShopOpenedEventPublisher
}
func NewEventPublisher(
shopOpenedEventPublisher ShopOpenedEventPublisher,
) EventPublisher {
return EventPublisher{
ShopOpenedEventPublisher: shopOpenedEventPublisher,
}
}
type ShopOpenedEventPublisher struct {
publisher appevent.ShopOpenedEventPublisher
bufSize int
}
func NewShopOpenedEventPublisher(
publisher appevent.ShopOpenedEventPublisher,
bufSize int,
) ShopOpenedEventPublisher {
return ShopOpenedEventPublisher{
publisher: publisher,
bufSize: bufSize,
}
}
func (p ShopOpenedEventPublisher) PublishShopOpenedEvent(ctx context.Context, event application.ShopOpenedEvent) <-chan domain.Error {
c := make(chan domain.Error, p.bufSize)
go func() {
defer close(c)
errSrc := p.publisher.PublishShopOpenedEvent(
ctx,
appevent.NewShopOpenedEvent(
event.OccurredOn(),
string(event.ShopID()),
event.OperatorID(),
event.OperatorType(),
),
)
for err := range errSrc {
c <- domain.ErrorUnknown(err)
}
}()
return c
}
type ShopOpenedEventSubscriber struct {
subscriber appevent.ShopOpenedEventSubscriber
bufSize int
}
func NewShopOpenedEventSubscriber(
subscriber appevent.ShopOpenedEventSubscriber,
bufSize int,
) ShopOpenedEventSubscriber {
return ShopOpenedEventSubscriber{
subscriber: subscriber,
bufSize: bufSize,
}
}
func (p ShopOpenedEventSubscriber) SubscribeShopOpenedEvent(ctx context.Context) (<-chan application.ShopOpenedEvent, domain.Error) {
src, err := p.subscriber.SubscribeShopOpenedEvent(ctx)
if err != nil {
return nil, domain.ErrorUnknown(err)
}
c := make(chan application.ShopOpenedEvent, p.bufSize)
go func() {
defer close(c)
for event := range src {
c <- application.NewShopOpenedEvent(
event.OccurredOn(),
domain.ShopID(event.ShopID()),
event.OperatorID(),
event.OperatorType(),
)
}
}()
return c, nil
}