Skip to content

Commit 3f6f4ff

Browse files
committed
fix linter
1 parent e767df3 commit 3f6f4ff

File tree

6 files changed

+34
-47
lines changed

6 files changed

+34
-47
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919

2020
# Go workspace file
2121
go.work
22-
.idea
22+
.idea
23+
config.yaml

cmd/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type Config struct {
1515
Port int `yaml:"port"`
1616
Validation struct {
1717
JWTHeaderName string `yaml:"jwt_header_name"`
18-
JWTValidationURL string `yaml:"jwt_url"`
19-
BoardValidationURL string `yaml:"board_url"`
18+
JWTValidationURL string `yaml:"jwt_validation_url"`
19+
BoardValidationURL string `yaml:"board_validation_url"`
2020
} `yaml:"validation"`
2121
} `yaml:"rest"`
2222
} `yaml:"apps"`

config-example.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apps:
2+
log_level: "DEBUG"
3+
rest:
4+
port: 8080
5+
validation:
6+
jwt_header_name: "<YOUR_JWT_HEADER_NAME>"
7+
jwt_validation_url: "<YOUR_JWT_VALIDATION_URL>"
8+
board_validation_url: "<YOUR_BOARD_VALIDATION_URL>"
9+
10+
storage:
11+
users:
12+
type: "in-memory"
13+
rooms:
14+
type: "in-memory"

config.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

internal/rest/ws/handler.go

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ func (ws *WebSocketHandler) messageHandler(conn *websocket.Conn, msg []byte) {
109109
case MessageConnectRequest:
110110
ws.registerUser(conn, v)
111111
case MessageNewDataRequest:
112-
ws.sendDataToRoom(conn, v)
112+
ws.sendDataToRoom(v)
113113
case MessageSetLeaderRequest:
114-
ws.setLeader(conn, v)
114+
ws.setLeader(v)
115115
}
116116
}
117117

118-
func (ws *WebSocketHandler) setLeader(conn *websocket.Conn, request MessageSetLeaderRequest) {
118+
//nolint:cyclop
119+
func (ws *WebSocketHandler) setLeader(request MessageSetLeaderRequest) {
119120
// Get the UserID from the JWT token
120121
userID, err := ws.validateJWT(request.Jwt)
121122
if err != nil {
@@ -146,13 +147,14 @@ func (ws *WebSocketHandler) setLeader(conn *websocket.Conn, request MessageSetLe
146147
}
147148

148149
// Set the leader
149-
if currentRoom.LeaderID == "0" {
150+
switch currentRoom.LeaderID {
151+
case "0":
150152
currentRoom.SetLeader(userID)
151153
ws.logger.Debug("User set as the leader", zap.String("userID", userID), zap.String("boardID", request.BoardID))
152-
} else if currentRoom.LeaderID == userID {
154+
case userID:
153155
currentRoom.SetLeader("0")
154156
ws.logger.Debug("Leader removed", zap.String("userID", userID), zap.String("boardID", request.BoardID))
155-
} else {
157+
default:
156158
return
157159
}
158160

@@ -177,7 +179,8 @@ func (ws *WebSocketHandler) setLeader(conn *websocket.Conn, request MessageSetLe
177179
}
178180
}
179181

180-
func (ws *WebSocketHandler) sendDataToRoom(conn *websocket.Conn, request MessageNewDataRequest) {
182+
//nolint:cyclop
183+
func (ws *WebSocketHandler) sendDataToRoom(request MessageNewDataRequest) {
181184
// Get the UserID from the JWT token
182185
userID, err := ws.validateJWT(request.Jwt)
183186
if err != nil {
@@ -278,7 +281,7 @@ func (ws *WebSocketHandler) unregisterUser(conn *websocket.Conn) {
278281
}
279282

280283
// Get the users ids
281-
var userIDs []string
284+
userIDs := make([]string, 0)
282285
for _, u := range currentRoom.GetUsers() {
283286
userIDs = append(userIDs, u.ID)
284287
}
@@ -304,7 +307,8 @@ func (ws *WebSocketHandler) registerUser(conn *websocket.Conn, request MessageCo
304307

305308
// Check if the user has access to the board
306309
if !ws.validateBoardAccess(request.BoardID, request.Jwt) {
307-
ws.logger.Debug("User not allowed to access this board", zap.String("userID", userID), zap.String("boardID", request.BoardID))
310+
ws.logger.Debug("User not allowed to access this board",
311+
zap.String("userID", userID), zap.String("boardID", request.BoardID))
308312
return
309313
}
310314

@@ -335,7 +339,7 @@ func (ws *WebSocketHandler) registerUser(conn *websocket.Conn, request MessageCo
335339
currentRoom.AddUser(newUser)
336340

337341
// Get the users ids
338-
var userIDs []string
342+
userIDs := make([]string, 0)
339343
for _, u := range currentRoom.GetUsers() {
340344
userIDs = append(userIDs, u.ID)
341345
}
@@ -375,26 +379,6 @@ func (ws *WebSocketHandler) sendUserConnected(request MessageUserConnectedRespon
375379
}
376380
}
377381

378-
func (ws *WebSocketHandler) sendUserFailedToConnect(conn *websocket.Conn, reason string) {
379-
failedUser, err := ws.userStorage.GetWhere(func(u *user.User) bool {
380-
return u.Conn == conn
381-
})
382-
if err != nil {
383-
return
384-
}
385-
err = failedUser.Conn.WriteJSON(MessageUserFailedToConnectResponse{
386-
Message: Message{
387-
Event: EventUserFailedToConnect,
388-
},
389-
UserID: failedUser.ID,
390-
Reason: reason,
391-
})
392-
if err != nil {
393-
return
394-
}
395-
failedUser.Conn.Close()
396-
}
397-
398382
func (ws *WebSocketHandler) sendUserDisconnected(request MessageUserDisconnectedResponse) {
399383
// Get the room
400384
currentRoom, _ := ws.roomStorage.Get(request.BoardID)

internal/rest/ws/messages.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type MessageNewDataRequest struct {
2121
Data Data `json:"data"`
2222
}
2323

24+
//nolint:tagliatelle
2425
type MessageUserConnectedResponse struct {
2526
Message
2627
BoardID string `json:"board_id"`
@@ -46,6 +47,7 @@ type MessageUserFailedToConnectResponse struct {
4647
Reason string `json:"reason"`
4748
}
4849

50+
//nolint:tagliatelle
4951
type MessageUserDisconnectedResponse struct {
5052
Message
5153
BoardID string `json:"board_id"`

0 commit comments

Comments
 (0)