Based on GopherCon 2018: Kat Zien - How Do You Structure Your Go Apps
There are two types of users - regular users and admins Regular users can send messages and join rooms Admins can create room, moderate messages and users
Room is just a space for users to chat
All users can send regular text messages or special commands.
Commands should start with special character /
and command name, such as rooms
or quit
.
-
User1
connect toWS Service
. -
WS Service
createUser1
goroutine -
Inside
User1
gouroutine all user messages/commands are read, parsed and send tocommand
channel. -
Another
Run
gouroutine insideWS Service
is readingcommand
channel and depending on command do some actions.4.1 Command
Join
will add User to room. If room does not exists it will create new one.4.2 Command
Rooms
will send back to user a list of existing rooms.4.3 Command
Users
will send back to user a list of users in the same room.4.4 Command
Quit
will remove user from room.4.5 If the are no commands at all the message will be sent to all users in the room.