Skip to content

Commit 0262846

Browse files
committed
adjust
1 parent f83d6fe commit 0262846

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

services/pubsub/memory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ func NewMemory() Broker {
2121
}
2222
}
2323

24-
func (p *Memory) Publish(_ context.Context, message Message) {
24+
func (p *Memory) Publish(_ context.Context, _topic string, message Message) {
2525
p.Lock()
2626

27-
topic, ok := p.topics[message.Topic]
27+
topic, ok := p.topics[_topic]
2828
if !ok {
2929
p.Unlock()
3030
return

services/pubsub/memory_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ func TestPubsub(t *testing.T) {
1717
wg sync.WaitGroup
1818

1919
testMessage = Message{
20-
Data: []byte("test"),
21-
Topic: "hello-world",
20+
Data: []byte("test"),
2221
}
2322
)
2423

@@ -39,7 +38,7 @@ func TestPubsub(t *testing.T) {
3938

4039
wg.Add(2)
4140
go func() {
42-
broker.Publish(ctx, testMessage)
41+
broker.Publish(ctx, "hello-world", testMessage)
4342
}()
4443

4544
wg.Wait()

services/pubsub/types.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ import "context"
99
type Message struct {
1010
// Data is the actual data in the entry.
1111
Data []byte `json:"data"`
12-
13-
// Topic is the topic of the message.
14-
Topic string `json:"topic"`
1512
}
1613

1714
// Subscriber receives published messages.
1815
type Subscriber func(Message)
1916

2017
type Broker interface {
21-
Publish(c context.Context, message Message)
18+
Publish(c context.Context, topic string, message Message)
2219
Subscribe(c context.Context, topic string, subscriber Subscriber)
2320
}

services/websocket/issue_comment_notifier.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func (n *websocketNotifier) DeleteComment(ctx context.Context, doer *user_model.
1919
return
2020
}
2121

22-
n.pubsub.Publish(ctx, pubsub.Message{
23-
Data: d,
24-
Topic: fmt.Sprintf("repo:%s/%s", c.RefRepo.OwnerName, c.RefRepo.Name),
22+
topic := fmt.Sprintf("repo:%s/%s", c.RefRepo.OwnerName, c.RefRepo.Name)
23+
n.pubsub.Publish(ctx, topic, pubsub.Message{
24+
Data: d,
2525
})
2626
}

0 commit comments

Comments
 (0)