GoShop: learning Go by building a 40-endpoint shopping backend
GoLang (the GoShop sample) is a complete shopping-site backend in a single Go binary: customers with JWT auth and TOTP two-factor, products, cart, orders, payments, shipping — reading from Redis, writing to PostgreSQL, with migrations embedded and applied at startup.
Why Go feels different, and why that is the point
Go has no classes, no inheritance, no exceptions. The sample leans into that: domains are
plain packages under internal/, errors are values you check and wrap
(if err != nil), and concurrency is goroutines with channels. Coming from C# or
Java, the first week feels restrictive; the second week you notice your code has fewer layers
and fewer surprises. The stack — chi router, pgx pool,
go-redis, JWT HS256, bcrypt — is the standard library-plus-small-packages idiom,
deliberately free of "framework magic".
Patterns worth studying in the code
- Idempotency — a shared
IdempotencyGuardmeans a retried payment request cannot charge twice. Any API that takes money needs this. - Degraded mode — when Redis is unreachable the service swaps in a no-op cache and keeps running slower instead of dying. Availability over purity.
- Embedded migrations — the schema ships inside the binary and applies on boot; a fresh checkout plus one command is a working system.
- Graceful shutdown — SIGTERM drains in-flight requests before exit.
Repo layout as a map
cmd/server (the entrypoint), internal/api (routing/middleware),
internal/<domain> (customers, products, cart, orders, payments, shipping),
internal/store (Postgres/Redis seams). If you have read the
Node.js GoShop article, you
will recognise the same domain split in a different language — that parallelism is deliberate.
Repository: github.com/bobhuang1/GoLang