Giter Club home page Giter Club logo

chat_app's Introduction

Real Time Chat Application

In order to run this app in Docker follow step but make sure you have docker install on you system

Run with Docker

https://github.com/bwithai/chat_app.git
cd chatapp
docker build -t chatapp .
docker run -p 8080:8080 chatapp

After starting the container, you can open a web browser and go to http://localhost:8080 to access the chat app.

Run locally

https://github.com/bwithai/chat_app.git
cd chatapp
go mod download
go run main.go

OR run with binary file

creates a binary executable file named main in the working directory (/chatapp in this case). This binary file contains the compiled version of your entire Go application, not just the main.go file.

# After go mod download
# Build the binary
go build -o main .
# Run the binary
./main

End Points

At Each time on application run. I refresh the database to delete all previous data. you can change it at db/db.go

Allows a user to create an account.

Allows a user to log in to their account. and set jwt cookies for front-end developer. login body { "email": "[email protected]", "password": "password" }

NoTe :

Once user login, It will Use the resources if it authorized, Keep in mind ADD 'Token' as a key and 'JWT token' as value into http.Header otherwise will be unauthorized for resources.

how to add token

After login the path /api/users/{userID}/profile will be use for checking the Authorization like: users having profile {userID} Authorized for ...

Allows a user to log out of their account. remove the set jwt cookies

Returns a list of all available chat rooms. with the list of user who join which room.

/api/users/{userID}/profile/chat/rooms/{roomId} Returns the details of a specific chat room in this case Room1, with list of users who join Room1.

Allow user to create Room send body { "id": "1", "name": "room1" }

7. ws://localhost:8000/api/users/1/profile/chat/room/1/messages [GET]

Allows a user to send a message to a specific chat room. As you can see its not a http request its a websocket to join the Room1 and broadcast message to every one who joined the room but make sure 1st create that room.

how to call websocket through postman

Returns a list of messages for a specific chat room.

Explanation of used methods

DB

In summary, this code creates a database and provides a way to access that database through the GetDB() function.

jwt-go

https://github.com/dgrijalva/jwt-go jwt library

auth_jwt

responsible for generate and validate jwt Token

router

Handles HTTP routing for a chat application. It uses the Gorilla Mux router package to handle HTTP requests and defines routes. The InitRouter function sets up the routing handlers for the different routes.

user

user that defines structs for handling user-related functionality in a chat application. The User struct defines the fields for a user's ID, username, email, and password, and uses gorm.Model to define default fields like ID, CreatedAt, UpdatedAt, and DeletedAt.

The Repository interface is used for storing and retrieving data from a database, and the Service interface defines methods that interact with the repository to create and login users.

context.Context is a type that is used to carry request-scoped data, cancellation signals, and deadlines across API boundaries and between processes.

  1. user_handler.go: responsible for handling an HTTP request to create a new user.
  2. user_service.go: responsible for creating a new user record in the database.
  3. user_db_interaction.go: responsible for interaction between user and database.

utils

encrypting password using bcrypt

chat_app's People

Contributors

bwithai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.