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.
-
User1connect toWS Service. -
WS ServicecreateUser1goroutine -
Inside
User1gouroutine all user messages/commands are read, parsed and send tocommandchannel. -
Another
Rungouroutine insideWS Serviceis readingcommandchannel and depending on command do some actions.4.1 Command
Joinwill add User to room. If room does not exists it will create new one.4.2 Command
Roomswill send back to user a list of existing rooms.4.3 Command
Userswill send back to user a list of users in the same room.4.4 Command
Quitwill remove user from room.4.5 If the are no commands at all the message will be sent to all users in the room.