A simple, real-time chat application built with Go and WebSockets, featuring a clean web interface for instant messaging.
- π Real-time messaging - Instant message delivery using WebSockets
- π₯ Multi-user support - Multiple users can chat simultaneously
- π Web-based interface - Clean, responsive HTML/CSS/JavaScript client
- β‘ Lightweight - Minimal dependencies, fast performance
- π― Simple setup - Get up and running in minutes
- π Cross-platform - Works on Linux, macOS, and Windows
- π± Mobile-friendly - Responsive design for mobile devices
π Live Demo: https://github.com/yuis-ice/go-chatapp-ai
- Go 1.21+ - Download Go
- Modern web browser - Chrome, Firefox, Safari, or Edge
-
Clone the repository
git clone https://github.com/yuis-ice/go-chatapp-ai.git cd go-chatapp-ai -
Install dependencies
go mod download
-
Run the server
go run main.go
-
Open your browser
http://localhost:8080 -
Start chatting!
- Enter a username
- Join the chat room
- Send messages in real-time
go-chatapp-ai/
βββ main.go # WebSocket server implementation
βββ go.mod # Go module dependencies
βββ go.sum # Dependency checksums
βββ static/
β βββ index.html # Web client interface
βββ .github/ # GitHub templates and workflows
βββ CONTRIBUTING.md # Contribution guidelines
βββ LICENSE # MIT license
βββ README.md # This file
- WebSocket Server: Built with Gorilla WebSocket
- Connection Hub: Manages client connections and message broadcasting
- Static File Server: Serves the web interface
- Real-time Communication: Handles user connections, disconnections, and message relay
- Responsive Design: Mobile-first, clean interface
- WebSocket Client: Establishes and maintains server connection
- Real-time Updates: Instant message display and user notifications
- Input Validation: Client-side message validation and sanitization
Client A ββ WebSocket ββ Go Server ββ WebSocket ββ Client B
β
Message Broadcast Hub
β
All Connected Clients
- Port:
8080(default) - Static Files: Served from
./static/ - WebSocket Endpoint:
/ws - CORS: Allowed for all origins (development mode)
// In main.go - modify these constants
const (
ServerPort = ":8080"
StaticDir = "./static/"
WSEndpoint = "/ws"
)# Run with live reload (if using air)
go install github.com/cosmtrek/air@latest
air
# Or run normally
go run main.go# Build binary
go build -o chat-server main.go
# Run binary
./chat-server# Run tests
go test ./...
# Run with coverage
go test -cover ./...# Dockerfile example
FROM golang:1.21-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o chat-server main.go
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/chat-server .
COPY --from=builder /app/static ./static
EXPOSE 8080
CMD ["./chat-server"]- Heroku: Ready for deployment with
Procfile - DigitalOcean: Works with App Platform
- AWS: Compatible with EC2, ECS, or Lambda
- Vercel/Netlify: Static files can be hosted separately
- No Authentication: Anyone can join with any username
- No HTTPS/WSS: Communication is not encrypted
- No Rate Limiting: Vulnerable to spam attacks
- CORS Wide Open: Accepts connections from any origin
- No Input Sanitization: Basic XSS protection only
- Implement user authentication
- Add HTTPS/WSS encryption
- Implement rate limiting
- Add proper input validation
- Configure CORS restrictions
- Add logging and monitoring
- Implement message persistence
- Add moderation features
We welcome contributions from the community! Please read our Contributing Guidelines for details on:
- π Reporting bugs
- π Requesting features
- π§ Setting up development environment
- π Code style guidelines
- π Pull request process
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Gorilla WebSocket - Excellent WebSocket library for Go
- Go Community - For the amazing ecosystem and resources
- Contributors - Thank you to everyone who contributes to this project
- π Bug Reports: Create an Issue
- π Feature Requests: Create an Issue
- π¬ Discussions: GitHub Discussions
- π§ Contact: jobs.fumiya@pm.me
- User authentication system
- Message history persistence
- Private messaging
- Chat rooms/channels
- File sharing support
- Mobile app (React Native/Flutter)
- Voice/video calling
- Message encryption
- Bot integration
- Emoji reactions
β Star this repository if you found it helpful!
Built with β€οΈ using Go and WebSockets
