Framework
geektutu/7days-golang avatar
geektutu/7days-golang

geektutu/7days-golang: Build Go Frameworks from Scratch in Seven Days

7 days golang programs from scratch (web framework Gee, distributed cache GeeCache, object relational mapping ORM framework GeeORM, rpc framework GeeRPC etc) 7天用Go动手写/从零实现系列

17,024 stars2,577 forksGoMIT

At a glance

What is it?
7days-golang is a tutorial series where each project rebuilds a well-known Go library from scratch over seven days, covering a web framework modeled on gin, a distributed cache modeled on groupcache, an ORM modeled on gorm and xorm, and an RPC framework built on top of net/rpc. Each day adds one architectural layer to the previous day's code, making the progression traceable.
Who is it for?
7days-golang suits Go developers who can already read Go code and want to understand the internals of a web framework, a distributed cache with consistent hashing, a basic ORM with reflection-driven schema mapping, or a JSON-RPC system with service discovery.
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 24 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 September 29, 2026, and from our analysis. They are not legal advice.

Editorial analysis

What the Repository Teaches and Who It Is For

7days-golang is a structured learning resource for Go developers who want to understand how production-grade Go libraries are designed, not just how to use them. Each of the four main series takes a well-known library as a reference, names it explicitly, and then rebuilds a simplified but functional version from Go's standard library up. The series are: Gee (modeled on gin), GeeCache (modeled on groupcache), GeeORM (modeled on gorm and xorm), and GeeRPC (built on top of the standard library `net/rpc` package).

The intended reader has working Go knowledge. The tutorials on the companion website at geektutu.com explain the design choices, but the repository itself is code, not prose. Each day's folder contains a runnable snapshot of the project at that stage, so you can read the diff between consecutive days to see exactly which lines implement a specific feature. A developer who has used gin but never looked at a trie-based router will find the Gee series directly useful. Someone who has debugged groupcache in production but does not know how consistent hashing distributes keys across nodes will find GeeCache useful.

Repository Structure: Four Projects, Seven Days Each

The repository is organized as a set of top-level directories, one per project. Inside each project directory, the code is split by day: `gee-web/day1-http-base` through `gee-web/day7-panic-recover`, for example. Each day directory is a standalone Go program at the state the tutorial reaches on that day. You do not need to run day one to understand day three; each snapshot is independent.

The four main series and their reference libraries are:

- `gee-web/`: a gin-like web framework (7 days) - `gee-cache/`: a groupcache-like distributed cache (7 days) - `gee-orm/`: a gorm and xorm-like ORM (7 days) - `gee-rpc/`: a net/rpc-based RPC framework with load balancing and service discovery (7 days)

The repository also contains `demo-wasm/` with four WebAssembly examples (Hello World, registering functions, DOM manipulation, and callbacks), and a `gee-bolt/` directory. Top-level documentation files `7days-golang-en.md` and `7days-golang.md` serve as English and Chinese indices. The `doc/` and `doc-en/` directories hold supporting documentation.

Gee: Building a Web Framework Layer by Layer

The Gee series is the most accessible entry point in the repository because gin is widely known and the gap between `net/http` and a full framework is concrete. Day one implements the `http.Handler` interface to show how gin wraps the standard library. Day two adds a Context type that bundles the request and response writer so handler functions do not need to import `net/http` directly. Day three adds a trie-tree router that matches dynamic path segments, replacing the map-based routing in the standard library. Days four and five add route groups and middleware chaining. Day six adds HTML template rendering. Day seven adds panic recovery.

The progression mirrors the actual architecture of gin: each day introduces exactly one layer that gin also implements. A developer who finishes the Gee series will understand why gin's `RouterGroup` exists, how middleware chaining is implemented using closures, and what the trie structure buys over a simple path map.

GeeCache: Consistent Hashing and Cache Breakdown Prevention

GeeCache models groupcache, which is the distributed cache library used by Google for several internal services. The series covers LRU eviction on day one, concurrent access on day two, an HTTP server for inter-node communication on day three, consistent hashing for key distribution on day four, multi-node communication on day five, and single-flight (preventing cache breakdown when many requests hit a missing key simultaneously) on day six. Day seven replaces the custom encoding with Protocol Buffers for inter-node communication.

The consistent hash implementation and the single-flight pattern are the two most transferable concepts in the series. Consistent hashing determines which node owns a key by mapping both keys and nodes onto a hash ring, so adding or removing a node only remaps a fraction of keys rather than all of them. Single-flight coalesces concurrent requests for the same missing key into a single backend fetch, which prevents the thundering-herd problem that causes cache breakdown.

GeeORM and GeeRPC: Reflection and Network Protocols

GeeORM implements a subset of what gorm provides: schema mapping from Go structs using reflection, basic CRUD operations, chain operations for building queries, hook callbacks, transaction support, and a database migration tool. The README notes that xorm's design is easier to understand than gorm v1, so GeeORM's interface references xorm while some implementation details reference gorm. Developers who have used either library but not inspected how `reflect` maps struct fields to SQL columns will find the day-two schema-mapping code directly useful.

GeeRPC extends Go's `net/rpc` package with protocol negotiation, a concurrent and asynchronous client, service registration using reflection, timeout handling, HTTP protocol support, load balancing across multiple servers, and a registry with heartbeat support. By day seven, GeeRPC is a simplified but functional RPC system with the three main distributed systems components that `net/rpc` itself omits: a service registry, load balancing, and protocol flexibility. The code is approximately 1,000 lines according to the README.

How to Use the Repository

The repository is a reading resource first. To use it, clone the repository and navigate to the day directory for the project and stage you want to study. The English documentation is in `doc-en/` and on the companion website at geektutu.com. The Chinese documentation is in `doc/`. The README includes a bilingual index that maps each day of each series to its directory and the corresponding tutorial page.

Each day directory contains a complete Go module. There are no shared dependencies between series and no monorepo build tool to run. To experiment with a specific day's code, navigate into its directory and run it using the standard Go toolchain. The repository carries an MIT license, so the code can be used freely including in commercial projects.

Limitations: Learning Tool, Not a Production Library

None of the four frameworks built in this series is intended for production use. They are pedagogical implementations that demonstrate the design pattern, not complete libraries. Gee lacks the full routing feature set and performance optimizations that gin includes. GeeCache lacks groupcache's integration with Google's infrastructure tooling. GeeORM covers a subset of gorm's features and does not implement connection pooling. GeeRPC's registry and load balancer work for the tutorial but are not hardened for high-availability scenarios.

The companion tutorials live on geektutu.com, not in the repository. If that website becomes unavailable, the repository code remains but the explanatory prose that describes why each design decision was made is gone. The English tutorial pages are at `geektutu.com/post/gee.html` and similar URLs; the repository's `doc-en/` directory contains some supporting material but is not a complete offline copy of the tutorials.

The repository has no formal releases. The last push was on 2026-09-05.

Alternative Approach: Reading Production Code Directly

The alternative to a tutorial series like 7days-golang is reading the source of the actual library you want to understand. gin, groupcache, gorm, and net/rpc are all available on GitHub with full commit histories. The advantage of reading production code is that you see the actual implementation, including performance optimizations, edge case handling, and the accumulated decisions from years of use. The disadvantage is that production code is dense: gin's router is significantly more complex than Gee's trie, and understanding it requires tracing through multiple files and understanding the project's history.

7days-golang's specific value is the progression structure. By constraining each day to a single new concept, the series isolates the mechanism from the surrounding complexity. For developers who find reading a 10,000-line production codebase overwhelming as a starting point, working through a 300-line daily snapshot that does one thing clearly is a more tractable path to the same understanding.

Editorial conclusion

7days-golang suits Go developers who can already read Go code and want to understand the internals of a web framework, a distributed cache with consistent hashing, a basic ORM with reflection-driven schema mapping, or a JSON-RPC system with service discovery. It is not suited for complete beginners to the language, since each series assumes you can follow Go code without explanations of syntax, and the companion tutorials are on an external website, not in the repository itself. Verify that you want to study a specific framework by reading its day-one file before committing to the full seven days; the projects are independent and can each be started without finishing the others.

Frequently asked questions

What is the 7days-golang tutorial series?

7days-golang is a repository that rebuilds four well-known Go libraries from scratch in seven-day increments: a gin-like web framework called Gee, a groupcache-like distributed cache called GeeCache, a gorm/xorm-like ORM called GeeORM, and a net/rpc-based RPC framework called GeeRPC. Each day adds one architectural layer to the previous day's code.

What Go frameworks does 7days-golang cover?

The repository covers four projects: a gin-modeled web framework, a groupcache-modeled distributed cache, a gorm and xorm-modeled ORM, and an RPC framework built on net/rpc with load balancing and service discovery. It also includes four WebAssembly examples.

Is 7days-golang suitable for Go beginners?

The series assumes you can already read Go code. Day one of each series starts with standard library types like `http.Handler` or `database/sql` without explaining Go syntax. The README recommends reading the Go language introduction at geektutu.com before starting the series.

Official sources

  1. geektutu/7days-golang on GitHub
  2. Issues
  3. License: MIT
  4. Project website
  5. README
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.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/geektutu-7days-golang.svg)](https://hysenlabs.com/projects/geektutu-7days-golang)