A Go-based backend application with WebSocket support, PostgreSQL database, and JWT authentication.
- RESTful API with Gorilla Mux router
- WebSocket support using Socket.IO
- PostgreSQL database with GORM ORM
- JWT authentication for secure API access
- CORS support for cross-origin requests
- Static file serving
- Environment configuration with dotenv
- Go 1.23.0 or higher
- PostgreSQL 15+ with PostGIS extension
- Git
git clone <repository-url>
cd coreUbuntu/Debian:
sudo apt-get install postgresql-15-postgis-3
# or for PostgreSQL 17
sudo apt install postgis postgresql-17-postgis-3macOS:
brew install postgresql postgiscp env.sample .env
# Edit .env with your database credentials and other settingsgo mod downloadgo run main.gogo run main.go -migratego run main.go -seedcore/
βββ constants/ # Application constants and error definitions
βββ models/ # Data models
βββ routes/ # HTTP route handlers and middleware
βββ services/ # Business logic and external services
β βββ db/ # Database operations and repositories
β βββ socket/ # WebSocket server implementation
βββ static/ # Static files served by the application
βββ types/ # Custom type definitions
βββ utils/ # Utility functions and helpers
βββ main.go # Application entry point
βββ go.mod # Go module dependencies
GET /- Home endpointPOST /packet- Main packet handler for authentication and other actionsGET /static/*- Static file serving
The application uses JWT tokens for authentication. Include the token in the Authorization header:
Authorization: <your-jwt-token>
WebSocket server runs alongside the HTTP server and handles real-time communication.
To run the application in development mode:
go run main.goThe server will start on the port specified in your .env file.
- Gorilla Mux - HTTP router and URL matcher
- GORM - ORM library for Go
- PostgreSQL Driver - Database driver for PostgreSQL
- Socket.IO - WebSocket library
- JWT - JSON Web Token implementation
- CORS - Cross-Origin Resource Sharing middleware
- Chats.go PinnedMsg *Message
gorm:"foreignKey:PinnedMsgID;references:ID"
[Add your license information here]
brew update brew install postgresql brew install postgis brew services start postgresql brew services list
brew services start postgresql psql postgres
ALTER ROLE postgres WITH PASSWORD 'TestTest!1453!';
brew services restart postgresql
server { listen 80; server_name socket.coolvibes.lgbt socket.coolvibes.app socket.coolvibes.io;
location /socket.io/ {
proxy_pass http://127.0.0.1:3002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
location /health {
return 200 "OK";
}
}
sudo systemctl reload nginx