LockGit/gochat: a pure-Go IM server with websocket and TCP in the same room
goim server write by golang !🚀
At a glance
- What is it?
- gochat is a lightweight instant messaging server written entirely in Go, with private messages, room broadcast, etcd service discovery and Redis as the delivery queue. It ships a Docker path for the full demo stack, and its documentation is a Chinese README plus an English version.
- Who is it for?
- Adopt gochat if you want to read or extend a small, complete IM pipeline in Go: connect, logic, task and api layers, rpcx over etcd, Redis as the queue, and a demo Docker image that brings the whole stack up. Do not adopt it if you need a production messaging service with documented operational guarantees; the README covers the demo path, not failure handling.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 86 days ago.
- What is it written in?
- Mainly Go, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- LockGit/gochat2,935 ★ · +4
| Repository | 2026-09-24 | 2026-11-25 |
|---|---|---|
| LockGit/gochat | 2.9k | 2.9k |
4 Stars in the last 62 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
What LockGit/gochat solves, and who the README is written for
gochat is a demo-scale instant messaging server written in pure Go. The README describes it as a lightweight IM system that supports private messages and room broadcast, with each layer talking to the others over RPC and with horizontal scaling in mind. The intended reader is someone who wants a working reference for how an IM backend is wired together, not someone shopping for a hosted chat product. The directory layout makes that explicit: api, connect, logic, task and site are separate top-level packages, and the README says each of them can scale horizontally.
The feature list is short and concrete. Websocket and TCP are both supported as client transports, and the README states that in the current version messages can cross between the two: a user connected over websocket and a user connected over TCP in the same room receive each other's messages. Service discovery is based on etcd, which the README argues makes adding capacity easier. Redis is used both as the message queue and as the session and counter cache. None of this is novel on its own; the value is that the pieces are assembled and readable in one repository.
That framing matters when you evaluate it. This is closer to a teaching implementation with a demo deployment than a product with an upgrade path. The repository has no published GitHub releases, and the README's update log mixes UI work, a Go 1.18 upgrade and a note about arbitrary module startup order. Treat the project as a codebase to learn from or fork, not as a dependency to pin.
How a message travels: api, logic, task and connect
The README walks through a private message from user A to user B, and the flow is the clearest description of the architecture. Both users log in through the api layer, authenticate against the connect layer to hold a long connection, and the connect layer makes an RPC call to the logic layer recording which connect serverId holds that user. Both users land in room 1 by default. When A sends a message, the api layer calls the logic layer, which pushes the message onto the queue. The task layer consumes it, uses the userId, roomId and serverId in the message to locate B's connect server, and calls that server over RPC. The connect layer then delivers into the room, which means walking the session list for that room.
For a private message, the task layer locates the target user's connect serverId from the userId and calls that connect layer directly over RPC.
Two implementation details are worth noting because they shape the code you will read. The connect layer is divided into buckets to reduce lock contention. And the README mentions CityHash being used to spread the hash distribution more evenly, with an architecture image for it. Neither detail is explained in depth in the text; you have to read the connect package. The message ID comes from a Snowflake implementation, and the README notes it could be split out as a separate service, claiming a theoretical ceiling of 4.096 million IDs per second.
Installing gochat: Docker first, then the module-by-module build
The README is direct about the fastest path: if you are only trying it out, use Docker. The image on Docker Hub is lockgit/gochat:1.18, and it already contains demo users. Clone the repository, then run the helper script, which the README says builds the modules and may take a while.
docker pull lockgit/gochat:1.18
git clone [email protected]:LockGit/gochat.git
cd gochat && sh run.sh dev 127.0.0.1The README notes that some systems lack sh, in which case you run ./run.sh dev 127.0.0.1 instead. After that, the login page is at http://127.0.0.1:8080/login and the chat room itself at http://127.0.0.1:8080. The demo credentials listed are demo/111111, test/111111 and admin/111111.
If you build it yourself, the README requires etcd and Redis to be running first, along with the database tables, and ports 7000, 7070 and 8080 to be free. TCP testing uses ports 7001 and 7002, which need firewall rules if you are on a VPS. The build uses the etcd tag:
go build -o gochat.bin -tags=etcd main.go
./gochat.bin -module logic
./gochat.bin -module connect_websocket
./gochat.bin -module task
./gochat.bin -module api
./gochat.bin -module siteThe README says to start the layers in that order, and warns that if you scale the connect layer, each serverId in the connect configuration must be different. A later update note says the modules now support arbitrary startup order, so the ordering instruction and that note sit side by side in the same document. If you want your own image, the Makefile has one target and takes a tag:
make build TAG=1.18The TCP client side is your problem, not the server's
The most useful limitation in the README is about TCP. Because TCP is a stream protocol at layer 4 rather than an application protocol, the server and client have to agree on how to frame messages. gochat implements packing and unpacking in pkg/stickpackage, with Pack and Unpack as the methods to trace. The README points at stickpackage_test.go and its Test_TcpClient method as the working example, and gives the command to run it:
go test -v -count=1 *.go -test.run Test_TcpClientIf you are writing an Android or iOS client, the README is explicit that you must implement the same packing and unpacking in your own language; the provided code is a Go demo, not a library you can link against. That is a real cost. A websocket client gets framing from the protocol; a TCP client inherits the job of parsing the stream correctly, and any mismatch in the framing rules produces a connection that appears to work and then delivers corrupt or missing messages.
The test also expects you to edit the marked @todo section with your own values before it will exercise message delivery, and it uses ports 7001 and 7002. The authToken used for the TCP connection is the user identity; the README says you can read it from the JSON returned by the web login API or look it up directly in Redis. When the server receives that token, it adds the user's TCP session to the session list for the corresponding room.
Beyond TCP framing, the README does not document rollback, reconnection semantics, message acknowledgement or what happens to queued messages if the task layer is down. Those gaps are the honest boundary of this project as documented.
Where gochat sits next to a heavier message bus
The README names its own alternatives rather than leaving you to guess. Redis is used as the message store and delivery carrier because it keeps the demo light, and the text says that in a real scenario it could be replaced by something heavier such as Kafka or RabbitMQ. That is the most meaningful architectural fork in the project. Redis as a queue is easy to run and easy to inspect, which suits a demo where you want to watch a message move from api to logic to task to connect. A log-based broker like Kafka changes the guarantees: retention, replay and consumer groups become broker features instead of things you build. If your requirement is that a message survives a task-layer restart, the Redis path in this repository does not document that it does.
The database choice follows the same pattern. The demo uses sqlite3 through gorm, and the README says it can be swapped for MySQL or another relational database by changing the driver. The schema is minimal, with a user table holding id, user_name, password and create_time. There is no message history table in the documented schema, so persistence of conversations is not part of what the README describes.
Service discovery is the one place where gochat commits to a specific piece of infrastructure: etcd, through rpcx. The README notes that watching etcd key-value changes lets each layer pick up new or removed service IPs dynamically. That is a genuine operational property, and it is also a dependency you cannot avoid if you want the multi-module setup to work.
Maintenance status, licence and what upgrading costs you
The repository is not archived. The last push was on 2026-09-01, which is recent enough that the code is not abandoned, but the README's own update log is a better guide to what has actually changed. The entries describe a UI rewrite in TypeScript and React in August 2022, a Go 1.18 upgrade and vendoring in May 2022, and a November 2025 note about supporting arbitrary module startup order. The repository has no published GitHub releases, so there is no versioned artifact to track; you are following the master branch.
The dependency picture is a mixed bag. go.mod pins Go 1.18 and pulls in gin, gorilla/websocket, go-redis v6.15.9, gorm v1.9.16, rpcx v1.7.4 and the rpcx-etcd bridge, among others. Several of these are old by the standards of the wider Go ecosystem, and the README warns against compiling on older Go versions. Because vendor is committed to the repository, a fresh clone builds without network access to the module proxy, at the cost of a repository the README puts at roughly 66 MB.
Upgrade cost is therefore mostly yours to manage. There is no release channel, no changelog beyond the README's dated bullets, and no migration tooling for the sqlite schema. If you fork this and change the database driver, the README's claim that only the driver needs changing is the only guidance you get.
The licence is MIT, which the README states in its License section and the repository carries as a LICENSE file. MIT is permissive and places few conditions on reuse or redistribution, but it comes with no warranty. Nothing here is legal advice; read the LICENSE file itself before you rely on it.
Editorial conclusion
Adopt gochat if you want to read or extend a small, complete IM pipeline in Go: connect, logic, task and api layers, rpcx over etcd, Redis as the queue, and a demo Docker image that brings the whole stack up. Do not adopt it if you need a production messaging service with documented operational guarantees; the README covers the demo path, not failure handling. Before committing, verify that etcd, Redis and the sqlite schema are in place, that ports 7000, 7070 and 8080 are free, and that you can start each module in the order the README lists.
Frequently asked questions
What is LockGit/gochat used for?
It is a lightweight instant messaging server written in pure Go that supports private messages and room broadcast, with websocket and TCP clients connecting to the same rooms. The README presents it as a demo-scale system with each layer able to scale horizontally.
How do I install gochat?
The README recommends Docker: pull lockgit/gochat:1.18, clone the repository, then run sh run.sh dev 127.0.0.1 and open http://127.0.0.1:8080/login. To build it yourself, run go build -o gochat.bin -tags=etcd main.go and start the logic, connect, task, api and site modules in that order, with etcd and Redis already running.
Is gochat free to use?
The repository is licensed under MIT, which the README states in its License section and the repository carries as a LICENSE file. That is a permissive licence, and the README does not describe any paid tier or hosted service.
How do I use gochat?
After the stack is running, log in at http://127.0.0.1:8080/login with one of the README's demo accounts, such as demo/111111, and open http://127.0.0.1:8080 to enter the chat room. The README states that message sending requires a logged-in state, and that users join room 1 by default.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/lockgit-gochat)Star history chart for your README
[](https://hysenlabs.com/projects/lockgit-gochat)Was this useful?