Skip to content

A simple websocket server written in go for blazing fast communication in the connected channels.

Notifications You must be signed in to change notification settings

Harshshah6/go-websocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Chat (Structured Go Project)

A real-time chat application built with Go and Gorilla WebSocket. This version is structured for scalability and maintainability using a layered architecture.


Features

  • Real-time chat with WebSockets
  • User join/leave notifications
  • Markdown support (**bold**, *italic*, `code`)
  • Multiline messages (Shift+Enter for new line)
  • Clean project structure (internal/, pkg/, cmd/)
  • Custom logger

Project Structure

go-chat/
├── cmd/
│   └── server/
│       └── main.go       # Entry point
│
├── internal/
│   ├── app/
│   │   └── app.go        # Wire dependencies + run server
│   ├── config/           # (future) env/config loader
│   ├── handlers/
│   │   └── chat.go       # WebSocket handler
│   ├── models/
│   │   └── message.go    # Data models
│   ├── services/
│   │   └── chat_service.go
│   └── store/
│       └── memory_store.go
│
├── pkg/
│   └── logger/
│       └── logger.go     # Custom logger wrapper
│
├── static/
│   └── index.html        # Frontend chat UI
│
├── Dockerfile
├── docker-compose.yml
├── go.mod
└── README.md

Requirements

  • Go 1.18+
  • Gorilla WebSocket package

Install dependencies:

go mod tidy

Running Locally

Start the app:

go run ./cmd/server

Visit in your browser:

http://localhost:8080

Running with Docker

  1. Build the image:
docker build -t go-chat .
  1. Run the container:
docker run -p 8080:8080 go-chat

Open in browser:

http://localhost:8080

Running with Docker Compose

docker compose up --build

To scale:

docker compose up --scale go-chat=3

(requires sticky sessions for WebSockets when load balancing)


License

MIT License. Free to use, modify, and distribute.