A lightweight publish‑subscribe service implemented in Go.
This project allows you to set up topics, publish messages to those topics, and have subscribers receive them in real time. Built for simplicity, clarity, and ease of extension.
This project leverages a combination of modern tools and technologies to ensure performance, scalability, and real-time data handling.
| Technology | Purpose |
|---|---|
| Go (Golang) | Core backend service, REST APIs, and WebSocket handling |
| WebSocket | Enables real-time bi-directional communication between client and server |
| Redis | Pub/Sub messaging system for instant data broadcast and event streaming |
| MongoDB | Database for storing user information, uploads, and message logs |
| Cloudinary | Cloud-based image upload and storage management |
| Gemini API | AI-powered caption generation or intelligent message processing |
| Docker | Containerization for consistent, scalable deployments across environments |
- Topic creation and management (publish/subscribe)
- Real-time message delivery to subscribed clients
- Built-in Docker support for easy deployment
- Environment configuration via
.envsample - Modular codebase making it easy to extend (commands, internal logic)
- Written in Go, optimized for performance and simplicity
- Go (version 1.x)
- Docker (optional, if you prefer container deployment)
- A terminal or command line interface
-
Clone the repository
git clone https://github.com/sachinggsingh/Go‑Pub‑Sub.git cd Go‑Pub‑Sub -
Copy the
.env.samplefile to.envand set your configuration valuescp .env.sample .env # Edit .env to adjust ports, topic defaults, etc. -
Build and run with Go
go build -o pubsub ./cmd ./pubsub
Or using Docker:
docker build -t go‑pubsub . docker run --env-file .env -p <your_port>:<container_port> go‑pubsub
-
Access the service (e.g., via HTTP endpoints or CLI commands) — see below for usage.
curl -X POST http://localhost:<port>/topics -H "Content-Type: application/json" -d '{"name":"my-topic"}'
curl -X POST http://localhost:<port>/topics/my-topic/publish -H "Content-Type: application/json" -d '{"message":"Hello, world!"}'
curl http://localhost:<port>/topics/my-topic/subscribe
This will keep the connection open and stream new messages as they come in.
(Adjust the URLs and ports per your .env configuration.)
cmd/— Application entry point, command/HTTP routing logicinternal/— Core logic: topic management, message routing, subscription handling.env.sample— Sample environment variablesDockerfile,.dockerignore— Container setup filesgo.mod,go.sum— Go module dependencies
- Simplicity & clarity — minimal dependencies, straightforward APIs
- Flexibility — easily extended to persistent back‑end, message queues, clustering
- Go’s concurrency model — leverages Go routines and channels for efficient message delivery
- Container‑ready — deployable via Docker in minutes
Contributions are very welcome! If you’d like to help:
- Fork the repo
- Create a feature branch (
git checkout -b feature/my‑feature) - Commit your changes and push (
git push origin feature/my‑feature) - Open a pull request describing your change
Please ensure code is well‑documented, maintains existing style, and includes tests (if applicable).
Maintained by Sachin Singh
- GitHub: sachinggsingh
- Email: sachinggsingh@gmail.com
- Link Sachin
- LinkedIn / Instagram: feel free to connect!
Thank you for checking out Go‑Pub‑Sub. Happy coding! 🎉