viniciusgabrielfo / golang-browser-based-chat

Golang Browser-Based Chat Application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Golang Browser-Based Chat Application

This is a browser-based chat application written in Golang. In general, you can talk in a chatroom with others authenticated users on /room.

The "database" users is managed in memory and you can register new users in /signup page.

This is a repository with 2 modules/services:

Responsible to manage users and the chatroom.

Responsible to handle the command /stock=symbol on the chatroom. Works as if you were a user within the chat.

Table of Contents

How to Use

It will only work if all services are running, If not please visit Infrastructure and Running Locally

  1. Access localhost:8000/login
  2. If you don't have a user, click to Signup or access localhost:8000/signup
  3. Login with your user and password (you will be redirected to chatroom, if not access localhost:8000/chatroom)

Infrastructure

The application needs the following services to run:

With Docker already installed locally, you can run the following Make command to run all the necessary infraestructure:

make start-docker-services

RabbitMQ

If you don't have RabbitMQ locally installed, to run a RabbitMQ ina a container run:

	docker run -d --rm \ 
    --name rabbitmq -p 15672:15672 \
    -p 5672:5672 rabbitmq:3-management

Running Locally

Requirements

Using Makefile (recommended)

To run any Make or Go command at the project root is necessary a go.work file. To generate run:

make generate-local-workspace

To run chatapp and stock-bot together you can run the following Make command:

make run-services-local

This command will run services in background and generate their logs on /logs folder

If you want to stop the execution, you can run:

make stop-services-local

Using Bash Directly

If you are not a fan of Makefile or can't use it, run the application directly by go run in root folder:

go work init
go work use -r . 
go run chat/cmd/main.go
go run stock-bot/cmd/main.go

It's important to generate a go.work to get a better experience with multi-modules

Endpoints

Endpoint Description Type Need JWT
GET /login Render the login page Render Page
GET /signup Render the signup page Render Page
GET /room Render the chatroom page Render Page
POST /auth Authenticate with the server API
POST /register Register a new user on the server API
GET /ws Connect to chatroom websocket API

POST /auth

Payload:

{
    "nick": "nick",
    "password": "pass"
}

POST /register

Payload:

{
    "nick": "nick",
    "password": "pass"
}

About

Golang Browser-Based Chat Application


Languages

Language:Go 68.8%Language:HTML 26.2%Language:Makefile 5.0%