A chat application for private messaging between users.
- Overview
- Features
- Technologies Used
- Getting Started
- Configuration
- API Endpoints
- Web Socket
- Deployment
- Contributing
- License
This project is a chat application that allows users to send private messages to each other securely. It enables users to discuss details of their transactions, such as invoices and banking details, within the app itself.
- 1-on-1 private messaging between users.
- Sender can edit or delete the message after it has been sent.
- Sender receives an acknowledgement when the message is successfully delivered to the recipient.
- Go programming language
- Gin framework for building APIs
- SQLC for database query generation
- Docker for containerization
- Viper for configuration management
- WebSocket for one-to-one communication
The project uses the following environment variables for configuration. Make sure to set these variables before running the application.
DB_DRIVER: Specifies the database driver to be used. In this case, it is set to postgres, indicating that the PostgreSQL database driver will be used.DB_SOURCE: Represents the connection string or the data source URL for connecting to the PostgreSQL database.SERVER_ADDRESS: Specifies the network address and port on which the server will listen for incoming HTTP requests.- ...
You can also provide configuration through a configuration file. Refer to the config.yaml file for an example configuration.
The following API endpoints are available:
POST /v1/users: Creates a new user. This endpoint is used to register a new user in the system.
GET /v1/ws: Establishes a WebSocket connection for one-to-one communication between users. This endpoint is used for real-time messaging.
GET /v1/hello: Returns a simple "Hello" message. This endpoint is used for testing purposes or as a basic health check.
-
POST /v1/messages: Retrieves a list of messages. This endpoint is used to fetch a list of messages. -
PATCH /v1/messages: Updates a message. This endpoint is used to edit or modify an existing message. -
DELETE /v1/messages: Deletes a message. This endpoint is used to remove a message from the system.
The project uses WebSocket for one-to-one communication between users. The WebSocket endpoint is:
ws://localhost:8000/v1/ws
- Sender id should be included in the URL query params. As an example,
ws://localhost:8080/v1/ws?sender_id=1 - Message body should be in JSON format. As an example,
{ "message":"good?", "receiver_id":3 } - After message is succcessfully delivered to the recepient, the recepient receives the message in the format which looks like
{ "id": 9, "message": " i am good", "sender_id": 1, "receiver_id": 3, "sent_at": "2023-05-17T13:31:44.673873Z" } - After message is successfully delivered to the recepient, sender receives an acknowledgement message which looks like
{ "Msg": "How are you?", "IsDelivered": true }
Follow these instructions to get the project up and running on your local machine.
- Install Docker in your system.
- Clone this repo using the command "git clone https://github.com/bishan20/Chat-system_golang.git".
- Open the project in Visual Studio Code.
- For Windows, OPEN start.sh and SELECT " LF " in end of line sequence.
- To run your project in docker, use command "docker-compose up" in your terminal.
- To test all REST API, check out the "postman-collection" folder and for web-socket, check out the instructions written above Web-Socket.
- After you are done with the testing, stop the server using the command "docker-compose down" in your terminal.