Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

coderloganli/gochat

Repository files navigation

GoChat - Multi-Container Deployment

This is a fork of LockGit/gochat with Docker Compose multi-container deployment support.

What's New

This fork adds production-ready multi-container deployment to the original gochat project:

  • βœ… 8 Independent Containers: Each service (etcd, redis, logic, connect-ws, connect-tcp, task, api, site) runs in its own container
  • βœ… Horizontal Scaling: Scale Logic, Connect, Task, and API services independently
  • βœ… Docker Compose: One-command deployment with make compose-dev or make compose-prod
  • βœ… Auto-Configuration: Container IPs automatically registered to etcd for proper RPC communication
  • βœ… Health Checks: Each service monitors its own health with auto-restart
  • βœ… Dev/Prod Configs: Separate configurations for development and production environments

Quick Start

# Start all services
make compose-dev
# Or manually
docker compose -f docker-compose.yml -f deployments/docker-compose.dev.yml up
# Visit the chat app
http://localhost:8080

Scaling Services

# Scale specific services
docker compose up --scale logic=3 --scale connect-ws=2 --scale task=2

Production Deployment

make compose-prod HOST_IP=<your-server-ip>

Architecture

×ば぀ N β†’ Business logic RPC (scalable) β”œβ”€β”€ connect-ws ×ば぀ Nβ†’ WebSocket handler (scalable) β”œβ”€β”€ connect-tcp ×ば぀ Nβ†’ TCP handler (scalable) β”œβ”€β”€ task ×ば぀ N β†’ Message worker (scalable) β”œβ”€β”€ api ×ば぀ N β†’ REST API (scalable) └── site β†’ Frontend">
β”œβ”€β”€ etcd β†’ Service discovery
β”œβ”€β”€ redis β†’ Message queue & cache
β”œβ”€β”€ logic ×ば぀ N β†’ Business logic RPC (scalable)
β”œβ”€β”€ connect-ws ×ば぀ Nβ†’ WebSocket handler (scalable)
β”œβ”€β”€ connect-tcp ×ば぀ Nβ†’ TCP handler (scalable)
β”œβ”€β”€ task ×ば぀ N β†’ Message worker (scalable)
β”œβ”€β”€ api ×ば぀ N β†’ REST API (scalable)
└── site β†’ Frontend

Documentation


Original README

gochat is a lightweight IM server implemented using pure go

  • gochat is an instant messaging system based on go. It supports private messages and room broadcast messages. It communicates between layers through RPC and supports horizontal expansion.
  • Supports websocket and TCP access, and supports websocket and TCP message interworking.
  • Based on etcd service discovery, making it convenient to scale and deploy.
  • Using redis as the carrier of message storage and delivery is very lightweight.
  • Because of Go's cross-compilation features, compiled binaries can run quickly on various platforms.
  • Clear architecture and directory structure.

Components

Language: golang
Database: sqlite3 (can be replaced with MySQL or other databases)
Database ORM: gorm
Service Discovery: etcd
RPC Communication: rpcx
Queue: redis (can be replaced with kafka or rabbitmq)
Cache: redis
Message ID: snowflake algorithm

Architecture Design

Service Discovery

Message Delivery

Features

  • Private messaging
  • Room broadcast messaging
  • Websocket support
  • TCP support
  • Horizontal scaling
  • Service discovery via etcd
  • Message queuing via Redis
  • Lightweight and fast

Directory Structure

.
β”œβ”€β”€ api # API layer, provides REST API services
β”œβ”€β”€ connect # Connection layer, handles long connections
β”œβ”€β”€ logic # Logic layer, handles business logic
β”œβ”€β”€ task # Task layer, consumes queue messages
β”œβ”€β”€ site # Frontend static files
β”œβ”€β”€ config # Configuration files
β”œβ”€β”€ db # Database initialization
β”œβ”€β”€ docker # Docker related files
β”œβ”€β”€ proto # RPC proto files
└── tools # Utility methods

Test Users

Default test users (username/password):

  • demo / 111111
  • test / 111111
  • admin / 111111

Commands

# Development
make compose-dev # Start dev environment
make compose-logs # View logs
make compose-ps # Check status
# Production
make compose-prod HOST_IP=x.x.x.x # Deploy to server
# Testing & Quality
make test # Run all tests
make test-coverage # Run tests with coverage
make fmt # Format code
make vet # Run go vet
make lint # Run linter
# Building
make build-binary # Build gochat binary
make build-image # Build Docker image
# Utilities
make clean # Clean up everything

CI/CD Pipeline

GitHub Actions Workflow

Automated CI/CD pipeline for testing, building, and deploying GoChat:

  • Test: Runs on every push and pull request

    • Go fmt check
    • Go vet static analysis
    • Unit and integration tests with coverage
    • Redis service container for tests
  • Build: Builds Docker image after tests pass

    • Multi-stage Docker build
    • Image caching for faster builds
  • Push: Pushes to Docker Hub (on push to branches)

    • Multiple tags: latest, <branch>, <git-sha>
    • Credentials via GitHub Secrets
  • Deploy: Optional deployment to environments

    • Development: Auto-deploy on dev branch
    • Staging: Auto-deploy on staging branch
    • Production: Manual approval on master branch

Setup GitHub Secrets

Configure these in repository Settings β†’ Secrets and variables β†’ Actions:

Required for Docker Hub:

  • DOCKERHUB_USERNAME - Your Docker Hub username
  • DOCKERHUB_TOKEN - Docker Hub access token

Optional for server deployment:

  • DEV_SERVER_HOST, DEV_SERVER_USER, DEV_SERVER_KEY
  • STAGING_SERVER_HOST, STAGING_SERVER_USER, STAGING_SERVER_KEY
  • PROD_SERVER_HOST, PROD_SERVER_USER, PROD_SERVER_KEY

Branch Strategy

  • dev β†’ Development environment (auto-deploy)
  • staging β†’ Staging environment (auto-deploy)
  • master β†’ Production environment (manual approval)

Manual Deployment

# Pull and deploy specific version
./scripts/deploy.sh dev latest
./scripts/deploy.sh staging abc123def
./scripts/deploy.sh prod latest

License

MIT License

Credits

Original Project: LockGit/gochat

Special thanks to LockGit for creating this excellent IM system.

About

goim server write by golang !πŸš€

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

  • Go 91.2%
  • Makefile 5.3%
  • Shell 1.8%
  • Dockerfile 1.1%
  • HTML 0.6%

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /