Skip to content

Commit 7ad643c

Browse files
committed
refactor: public
1 parent cf16959 commit 7ad643c

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

internal/service/chat/chat_errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ var (
1414
ErrJoinDirectChat = errors.New("joining direct chat is not possible")
1515
ErrRecipientNotFound = errors.New("recipient not found")
1616
ErrMessageStoreCreation = errors.New("failed to create message store for chat")
17+
ErrPublishEvent = errors.New("failed to publish event to streamer")
1718
)

internal/service/chat/chat_service.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,16 @@ func (s *ChatService) CreateDirect(ctx context.Context, userID model.UserID, rec
185185
return nil, &vali.Varror{Error: service.ErrProtoMarshaling}
186186
}
187187

188-
s.eventPublisher.Publish(&eventsv1.StreamEvent{
188+
err = s.eventPublisher.Publish(&eventsv1.StreamEvent{
189189
SenderUserId: userID,
190190
ReceiversUserId: []model.UserID{
191191
finalRecipientUserID,
192192
},
193193
Payload: payloadProtoBuf,
194194
})
195+
if err != nil {
196+
return nil, &vali.Varror{Error: ErrPublishEvent}
197+
}
195198

196199
return chatDTO, nil
197200
}

internal/service/common_errors.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ package service
22

33
import "errors"
44

5-
var (
6-
ErrProtoMarshaling = errors.New("proto marshaling failed")
7-
)
5+
var ErrProtoMarshaling = errors.New("proto marshaling failed")

utils/random/random.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
const UserIDLength = 8
1010

1111
var (
12-
min = int64(math.Pow(10, float64(UserIDLength)-1))
13-
max = int64(math.Pow(10, float64(UserIDLength))) - 1
12+
minInt = int64(math.Pow(10, float64(UserIDLength)-1))
13+
maxInt = int64(math.Pow(10, float64(UserIDLength))) - 1
1414
)
1515

1616
func GenerateUserID() int {
@@ -22,7 +22,7 @@ func GenerateUserID() int {
2222
panic(err)
2323
}
2424

25-
randomNumber = int64(binary.BigEndian.Uint64(buf))%(max-min+1) + min
25+
randomNumber = int64(binary.BigEndian.Uint64(buf))%(maxInt-minInt+1) + minInt
2626

2727
return int(randomNumber)
2828
}

0 commit comments

Comments
 (0)