Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rafaelsouzaribeiro/web-chat-websocket-in-golang
Web chat with WebSocket, Redis, and Cassandra, including notifications for logged-in and logged-out users, and emoji support, implemented in Go and JavaScript.
https://github.com/rafaelsouzaribeiro/web-chat-websocket-in-golang
cassandra chat clean-architecture emojis golang javascrit login logout redis websocket
Last synced: 14 days ago
JSON representation
Web chat with WebSocket, Redis, and Cassandra, including notifications for logged-in and logged-out users, and emoji support, implemented in Go and JavaScript.
- Host: GitHub
- URL: https://github.com/rafaelsouzaribeiro/web-chat-websocket-in-golang
- Owner: rafaelsouzaribeiro
- Created: 2024-06-29T20:03:52.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-10-22T21:02:10.000Z (3 months ago)
- Last Synced: 2024-10-23T15:29:17.400Z (3 months ago)
- Topics: cassandra, chat, clean-architecture, emojis, golang, javascrit, login, logout, redis, websocket
- Language: Go
- Homepage:
- Size: 313 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Web chat with WebSocket, Redis and Cassandra, including notifications for logged-in and logged-out users, and emoji support, implemented in Go and JavaScript.
To use messages and track connected and disconnected users with only a map variable, use this project.here.
See also an MQTT chat application created using Go, JavaScript, CSS, and HTMLIf you want to use a chat with message tracking and the ability to track connected and disconnected users using Redis or Cassandra, this is the project you need.
1 - Navigate to the /cmd directory.
2 - Set within the cmd/main.go code: `f := factory.NewFactory(factory.Cassandra, Conf)`, using either factory.Redis or factory.Cassandra.
3 - Run: main.go
4 - access via browser: http://localhost:8080/chat
5 - being able to open in multiple tabs and connect multiple users
6 - connect user and send message
You can also run it through the dockerfile. I am using Docker Engine version 27.1.2:
Redis:```
FROM golang:1.23 AS builder
WORKDIR /app
COPY . .RUN go mod download
RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-w -s" -o main ./cmd/main.goFROM scratch
WORKDIR /appENV HOST_REDIS_DOCKER="172.17.0.4"
COPY --from=builder /app/main /app/
COPY --from=builder /app/cmd/.env /app/CMD ["./main"]
```
Cassandra:
```
FROM golang:1.23 AS builder
WORKDIR /app
COPY . .RUN go mod download
RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-w -s" -o main ./cmd/main.goFROM scratch
WORKDIR /appENV HOST_CASSANDRA_DOCKER="172.17.0.4"
COPY --from=builder /app/main /app/
COPY --from=builder /app/cmd/.env /app/CMD ["./main"]
```
To create the keyspace and tables in Cassandra, just run the following Makefile commands in the project root:```
Create KeysPace: make create-keyspace
Create tables: make migrateup
Drop tables and keyspace: make migratedown```
If you don't have make installed, install it with the following command:
```
sudo apt install make```
To run Redis in Docker, navigate to the internal/infra/database/redis directory and run:
```
sudo docker compose up
```
If you want to use Cassandra, navigate to the internal/infra/database/cassandra directory and execute the same command.
To use Redis and Cassandra as Docker containers and access them from another WebSocket container, you need to determine the internal IP address of the Redis or Cassandra container. First, with Redis or Cassandra running, execute the following command with the container name:```
sudo docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redis
``````
sudo docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cassandra
```
After running this command, you can set the Redis or Cassandra IP address in the Dockerfile using the ENV instruction:```
ENV HOST_CASSANDRA_DOCKER=ip_address_from_inspect```
```
ENV HOST_REDIS_DOCKER=ip_address_from_inspect```