Skip to content

Commit 6dc2cfb

Browse files
committed
Containerize chat-app and create docker network for all services. Connect to Cassandra db
1 parent de919f5 commit 6dc2cfb

12 files changed

Lines changed: 228 additions & 15 deletions

File tree

backend/Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM golang:1.23.3
4+
5+
# Set destination for COPY
6+
WORKDIR /backend
7+
8+
RUN apt update && apt install -y postgresql-client
9+
10+
# Download Go modules
11+
COPY go.mod go.sum ./
12+
COPY . .
13+
RUN go mod tidy
14+
15+
# Copy the source code. Note the slash at the end, as explained in
16+
# https://docs.docker.com/reference/dockerfile/#copy
17+
COPY *.go ./
18+
19+
# Build
20+
RUN CGO_ENABLED=0 GOOS=linux go build -o /chatapp
21+
22+
# Optional:
23+
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
24+
# But we can document in the Dockerfile what ports
25+
# the application is going to listen on by default.
26+
# https://docs.docker.com/reference/dockerfile/#expose
27+
EXPOSE 8080
28+
29+
# Run
30+
CMD ["/chatapp"]

backend/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ create_migration:
44
migrate create -ext=sql -dir=postgres/migrations -seq init
55

66
migrate_up:
7-
migrate -path=postgres/migrations -database "postgresql://${PSQL_USER}:${PSQL_PASSWORD}@${PSQL_HOST}:${PSQL_PORT}/${PSQL_DBNAME}?sslmode=${PSQL_SSLMODE}" -verbose up
7+
migrate -path=postgres/migrations -database "postgresql://${PSQL_USER}:${PSQL_PASSWORD}@localhost:${PSQL_PORT}/${PSQL_DBNAME}?sslmode=disable" -verbose up
88

99
migrate_down:
1010
migrate -path=postgres/migrations -database "postgresql://${PSQL_USER}:${PSQL_PASSWORD}@${PSQL_HOST}:${PSQL_PORT}/${PSQL_DBNAME}?sslmode=${PSQL_SSLMODE}" -verbose down

backend/cassandra/client.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package cassandra
2+
3+
import (
4+
"fmt"
5+
"log"
6+
// "time"
7+
8+
"github.com/gocql/gocql"
9+
)
10+
11+
func CassandraClient() {
12+
fmt.Println("Creating Cassandra session")
13+
cluster := gocql.NewCluster("cassandra-node1:9042")
14+
// cluster.Authenticator = gocql.PasswordAuthenticator{
15+
// Username: "user",
16+
// Password: "password"
17+
// }
18+
cluster.ProtoVersion = 4
19+
// cluster.Keyspace = "keyspace"
20+
// cluster.Port = 29042
21+
// cluster.CQLVersion = "5.0.0"
22+
// cluster.ConnectTimeout = time.Second * 6
23+
cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(gocql.DCAwareRoundRobinPolicy("cassandra-node1"))
24+
fmt.Println("3")
25+
session, err := cluster.CreateSession()
26+
if err != nil {
27+
log.Fatal(err)
28+
}
29+
defer session.Close()
30+
fmt.Println("Connected to Cassandra Nodes:")
31+
for _, host := range cluster.Hosts {
32+
fmt.Println("- Node:", host)
33+
}
34+
// session, err := cluster.CreateSession()
35+
// if err != nil {
36+
// panic(err)
37+
// }
38+
// defer session.Close()
39+
// fmt.Println("5")
40+
// fmt.Println("Connected to Cassandra Nodes:")
41+
// for _, host := range cluster.Hosts {
42+
// fmt.Println("- Node:", host)
43+
// }
44+
45+
// Print which node is being used for a query
46+
// var clusterID string
47+
// iter := session.Query("SELECT release_version FROM system.local").Iter()
48+
// for iter.Scan(&clusterID) {
49+
// fmt.Println("Running query on:", clusterID)
50+
// }
51+
// if err := iter.Close(); err != nil {
52+
// log.Fatal("Error closing iterator:", err)
53+
// }
54+
}

backend/cassandra/data.cql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE KEYSPACE IF NOT EXISTS chat_app WITH REPLICATION =
2+
{ 'class' : 'SimpleStrategy', 'replication_factor' : '1' };
3+
4+
CREATE TABLE IF NOT EXISTS chat_app.messages (
5+
circle_id TEXT, -- Partition key (groups messages by circle)
6+
created_at TIMESTAMP, -- Clustering key (orders messages by time)
7+
message_id UUID, -- Unique ID for the message
8+
author_id TEXT, -- ID of the user who sent it
9+
content TEXT, -- message
10+
PRIMARY KEY (circle_id, created_at, message_id)
11+
) WITH CLUSTERING ORDER BY (created_at DESC);

backend/docker-compose.yml

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ services:
22
postgres:
33
image: postgres:latest
44
container_name: postgres
5+
hostname: postgres
6+
networks:
7+
- backend-net
58
ports:
69
- "5432:5432"
710
environment:
8-
POSTGRES_USER: admin
11+
POSTGRES_USER: ${PSQL_USER}
912
POSTGRES_PASSWORD: ${PSQL_PASSWORD}
1013
POSTGRES_DB: ${PSQL_DBNAME}
1114
volumes:
1215
- postgres-data:/var/lib/postgresql/data
1316
redis:
1417
image: redis:latest
1518
container_name: redis
19+
networks:
20+
- backend-net
21+
hostname: redis
1622
ports:
1723
- "6379:6379"
1824
volumes:
@@ -22,28 +28,97 @@ services:
2228
image: apache/kafka:latest
2329
container_name: kafka
2430
hostname: kafka
31+
networks:
32+
- backend-net
2533
ports:
2634
- "9092:9092"
2735
- "9093:9093"
2836
environment:
37+
# Configure listeners for both docker and host communication
38+
KAFKA_LISTENERS: CONTROLLER://localhost:9091,HOST://kafka:9092,DOCKER://kafka:9093
39+
KAFKA_ADVERTISED_LISTENERS: HOST://localhost:9092,DOCKER://kafka:9093
40+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,DOCKER:PLAINTEXT,HOST:PLAINTEXT
41+
42+
# Settings required for KRaft mode
2943
KAFKA_NODE_ID: 1
30-
KAFKA_PROCESS_ROLES: "controller,broker"
31-
KAFKA_CONTROLLER_QUORUM_VOTERS: "1@kafka:9093"
32-
KAFKA_LISTENERS: "PLAINTEXT://kafka:9092,CONTROLLER://kafka:9093"
33-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://localhost:9092"
34-
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT"
35-
KAFKA_INTER_BROKER_LISTENER_NAME: "PLAINTEXT"
36-
KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
44+
KAFKA_PROCESS_ROLES: broker,controller
45+
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
46+
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9091
47+
48+
# Listener to use for broker-to-broker communication
49+
KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER
50+
51+
# Required for a single node cluster
52+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
53+
54+
3755
KAFKA_LOG_DIRS: "/var/lib/kafka/data"
3856
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
39-
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
4057
KAFKA_LOG_RETENTION_HOURS: 168
4158
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
4259
CLUSTER_ID: "Mk3OEYBSD34fcwNTJENDM2Qk"
4360
volumes:
4461
- kafka-data:/var/lib/kafka/data
62+
cassandra-node1:
63+
image: cassandra:latest
64+
container_name: cassandra-node1
65+
hostname: cassandra-node1
66+
networks:
67+
- backend-net
68+
environment:
69+
CASSANDRA_CLUSTER_NAME: "cassandra-cluster"
70+
CASSANDRA_SEEDS: "cassandra-node1,cassandra-node2,cassandra-node3"
71+
CASSANDRA_NUM_TOKENS: 128
72+
ports:
73+
- "9042:9042"
74+
volumes:
75+
- cassandra-data-node1:/var/lib/cassandra
76+
77+
cassandra-node2:
78+
image: cassandra:latest
79+
container_name: cassandra-node2
80+
hostname: cassandra-node2
81+
networks:
82+
- backend-net
83+
depends_on:
84+
- cassandra-node1
85+
environment:
86+
CASSANDRA_CLUSTER_NAME: "cassandra-cluster"
87+
CASSANDRA_SEEDS: "cassandra-node1"
88+
CASSANDRA_NUM_TOKENS: 128
89+
volumes:
90+
- cassandra-data-node2:/var/lib/cassandra
91+
92+
cassandra-node3:
93+
image: cassandra:latest
94+
container_name: cassandra-node3
95+
hostname: cassandra-node3
96+
networks:
97+
- backend-net
98+
depends_on:
99+
- cassandra-node1
100+
environment:
101+
CASSANDRA_CLUSTER_NAME: "cassandra-cluster"
102+
CASSANDRA_SEEDS: "cassandra-node1"
103+
CASSANDRA_NUM_TOKENS: 128
104+
volumes:
105+
- cassandra-data-node3:/var/lib/cassandra
106+
chat-app:
107+
build: .
108+
container_name: chat-app
109+
networks:
110+
- backend-net
111+
depends_on:
112+
- cassandra-node1
113+
114+
networks:
115+
backend-net:
116+
driver: bridge
45117

46118
volumes:
47119
postgres-data:
48120
redis-data:
49-
kafka-data:
121+
kafka-data:
122+
cassandra-data-node1:
123+
cassandra-data-node2:
124+
cassandra-data-node3:

backend/go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.23.3
44

55
require (
66
github.com/IBM/sarama v1.45.0
7+
github.com/gocql/gocql v1.7.0
78
github.com/golang-jwt/jwt/v5 v5.2.1
89
github.com/google/uuid v1.6.0
910
github.com/gorilla/websocket v1.5.3
@@ -20,6 +21,7 @@ require (
2021
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
2122
github.com/eapache/queue v1.1.0 // indirect
2223
github.com/golang/snappy v0.0.4 // indirect
24+
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
2325
github.com/hashicorp/errwrap v1.0.0 // indirect
2426
github.com/hashicorp/go-multierror v1.1.1 // indirect
2527
github.com/hashicorp/go-uuid v1.0.3 // indirect
@@ -34,8 +36,10 @@ require (
3436
github.com/klauspost/compress v1.17.11 // indirect
3537
github.com/pierrec/lz4/v4 v4.1.22 // indirect
3638
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
39+
github.com/rogpeppe/go-internal v1.13.1 // indirect
3740
golang.org/x/crypto v0.32.0 // indirect
3841
golang.org/x/net v0.34.0 // indirect
3942
golang.org/x/sync v0.10.0 // indirect
4043
golang.org/x/text v0.21.0 // indirect
44+
gopkg.in/inf.v0 v0.9.1 // indirect
4145
)

backend/go.sum

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
github.com/IBM/sarama v1.45.0 h1:IzeBevTn809IJ/dhNKhP5mpxEXTmELuezO2tgHD9G5E=
22
github.com/IBM/sarama v1.45.0/go.mod h1:EEay63m8EZkeumco9TDXf2JT3uDnZsZqFgV46n4yZdY=
3+
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY=
4+
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
5+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
6+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
37
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
48
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
59
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
@@ -19,8 +23,11 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
1923
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
2024
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
2125
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
26+
github.com/gocql/gocql v1.7.0 h1:O+7U7/1gSN7QTEAaMEsJc1Oq2QHXvCWoF3DFK9HDHus=
27+
github.com/gocql/gocql v1.7.0/go.mod h1:vnlvXyFZeLBF0Wy+RS8hrOdbn0UWsWtdg07XJnFxZ+4=
2228
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
2329
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
30+
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
2431
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
2532
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
2633
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -29,6 +36,8 @@ github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+
2936
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
3037
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
3138
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
39+
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
40+
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
3241
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
3342
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
3443
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
@@ -60,6 +69,12 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
6069
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
6170
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
6271
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
72+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
73+
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
74+
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
75+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
76+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
77+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
6378
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
6479
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
6580
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -68,6 +83,8 @@ github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5X
6883
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
6984
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
7085
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
86+
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
87+
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
7188
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7289
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
7390
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -118,6 +135,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
118135
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
119136
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
120137
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
138+
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
139+
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
121140
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
122141
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
123142
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

backend/kafka/producer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ import (
1212
"github.com/Leo7Deng/ChatApp/websockets"
1313
)
1414

15-
var brokers = []string{"localhost:9092"}
1615
var topic = "chat"
17-
16+
var brokers = []string{"kafka:9093"}
1817
var kafkaProducer sarama.SyncProducer
1918

2019
func WebsocketProducer(ctx context.Context, hub *websockets.Hub) {

backend/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"fmt"
66
"log"
77
"net/http"
8+
"net"
89
"sync"
910

1011
"github.com/Leo7Deng/ChatApp/auth"
12+
"github.com/Leo7Deng/ChatApp/cassandra"
1113
"github.com/Leo7Deng/ChatApp/circles"
1214
"github.com/Leo7Deng/ChatApp/kafka"
1315
"github.com/Leo7Deng/ChatApp/middleware"
@@ -21,7 +23,20 @@ type api struct {
2123
addr string
2224
}
2325

26+
func GetOutboundIP() net.IP {
27+
conn, err := net.Dial("udp", "8.8.8.8:80")
28+
if err != nil {
29+
log.Fatal(err)
30+
}
31+
defer conn.Close()
32+
33+
localAddr := conn.LocalAddr().(*net.UDPAddr)
34+
35+
return localAddr.IP
36+
}
37+
2438
func main() {
39+
fmt.Println("IP Address: ", GetOutboundIP())
2540
err := godotenv.Load()
2641
if err != nil {
2742
fmt.Printf("Error loading .env file: %v", err)
@@ -50,6 +65,8 @@ func main() {
5065
go hub.Run()
5166
fmt.Println("Websocket server started", hub)
5267

68+
cassandra.CassandraClient()
69+
5370
mux.HandleFunc("/api/register", middleware.AddCorsHeaders(auth.RegisterHandler))
5471
mux.HandleFunc("/api/login", middleware.AddCorsHeaders(auth.LoginHandler))
5572
mux.Handle("/api/circles", middleware.AddCorsHeaders(

backend/postgres/circles_repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func LoadCircleUserMap() (map[string]map[string]bool, error) {
228228
fmt.Fprintf(os.Stderr, "Unable to acquire a connection from the pool: %v\n", err)
229229
return nil, err
230230
}
231+
fmt.Println("LoadCircleUserMap")
231232
defer conn.Release()
232233

233234
rows, err := conn.Query(

0 commit comments

Comments
 (0)