Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Channels are popular in golang for sharing data. In the golang training i took,
### Organisation of files
| File name | Description |
| -----| ---|
| main.go | This is startup file. The `init()` , which by defualt gets called first before `main()` initializes the necessary configuration such as the server host,port and log files . The `main()` creates a `chat.NewServer` type and starts a `go routine` to listen on the server. Apart from it, the `main()` also create a webserver and route handler to load the inital page of the application |
| main.go | This is startup file. The `init()` , which by default gets called first before `main()` initializes the necessary configuration such as the server host,port and log files . The `main()` creates a `chat.NewServer` type and starts a `go routine` to listen on the server. Apart from it, the `main()` also create a webserver and route handler to load the inital page of the application |
| server.go | The server file has `Server` struct defined with essential fields. The `Server` glues everything together. `server.go` has different functions defined for perfoming activities in a chat room such as <ul><li> Adding a user to chatroom</li> <li> Removing a user from chat room</li><li>Brodcasting message to all users who are connected to the chat room</li><li>has the history of all the messages so far created</li></ul> The `Listen()` is triggerd as a `go routine` from `main()`. The `Listen()` handles a separate http route `/chat` which is used by `ws` protocol for communicating with the server. The `Listen()` has an infinite `for` loop that has a `select` to match case for different channel operations |
| user.go | The `user.go` is representation of a user. I have a struct defined called `User` which has the props for the user. `NewUser` gets created whenever a new websocket connection is established. There are two main functions here `listenRead()` and `listenWrite()` that helps in listening for new incoming and outgoing messages. `listenWrite()` is triggered as a separate `go routine` |
| message.go | This is a simple struct that defines how a message look like |
Expand Down