Chat server written in Golang. Multiple clients can connect via telnet. HTTP REST API to send messages and query for channel message history.
Place this whole folder inside the GOPATH
go run server.go -configfile="<config_file_full_path>"
Change the config.json file to change the configuration (like host, port number, log file locations) of the server.
Go module will install the packages required
-
There can be multiple connected clients at the same time.
-
All the connected clients at a time have unique usernames.
-
Usernames can be reused (after the client with same username has closed the connection)
-
Client can send a direct message to another client provided that he has the correct username of the client.
-
Any client can create a new channel provided a channel with same name doesn’t exist already.
-
Both public and private Channels can be created
• Private channels can only be joined by clients which have the unique key of the channel. • Public channels can be joined by anyone. Mention key as nil.
-
A client can send message to all connected clients using the channel “all”.
-
A client can block and unblock a specific client i.e. a client can choose to unsubscribe from another client’s messages.
-
A client can view its own blocklist.
-
A client can view the channel information:
• Creator of the channel • Time the channel was created • Channel access(public/private) • Channel key • Members of the channel
This information can only be viewed if a client has joined the channel.
-
Client can view the channels that he/she has joined.
-
HTTP REST API for posting messages to a channel.
-
HTTP REST API for reading message history of a channel (Requires key if the channel is private).
-
A configuration file saves all the configuration (like host, port number, log file locations) of the chat server
-
Error logging to log all the errors.
-
Message logging to log all the messages (both to channel and direct messages)
-
Activity logging to log activities on the chat server:
• New User • Channel Creation • Join Channel • Leave Channel • Send Message to a channel • Send Direct Message • Block User • Unblock User • Read message history (API) • Delete User
Unit testing is also implemented with 91.8% coverage.
- Use of local database to store log files and message history.
- Channel name is not case sensitive.
- No concept of channel admin
- If a client is typing a command (to perform some action) in the telnet server and another client sends him a message, he has to type the command again
- \options – To print the available options
- \channels – To print the list of client’s subscribed channels
- \info all – To print the information about the channel “all”
- \new tech w2ci93 private – To create a private channel “tech” with the key “w2ci93”
- \new gen nil public – To create a public channel “gen” with the key “nil”
- \join tech w2ci93 – To join the private channel “tech”. Key should be valid to join a private channel.
- \join gen nil - To join the public channel “gen”.
- \leave tech – To leave the channel “tech”
- \sendc gen Welcome to the channel – To send a message “Welcome to the channel” to channel “gen”
- \sendu rish Hey rish – To send a direct message “Hey rish” to the user “rish”
- \block rish – To block the user “rish”
- \unblock rish – To unblock the user “rish”
- \blocklist – To print the blocklist of the client
- \close – To close the connection
- curl -X POST -d "{'channel': 'tech','key':'nil','msg':'Hello Hi'}" localhost:8080/send – To send a message to channel gen
- curl -X GET localhost:8080/history/tech/w2ci93 – To get message history of the channel tech. Key should be specified in the last. (Use key to be nil if accessing public channel)