How amar-preet/go-crud-twirp works
Project type and purpose
• This is a backend Go service that implements a simple CRUD API (“Albums”) over HTTP using Twitch’s Twirp RPC framework, backed by a PostgreSQL database.
• It also provides a command-line client (in cmd/client) that uses the generated Twirp client to invoke the server.
File structure
• Top-level:
• cmd/server: entry point for the HTTP/Twirp server
• cmd/client: entry point for a CLI client
• rpc/twirpAPI: the .proto definition, and generated Twirp server/client stubs
• internal/twirpAPI: hand-written server implementation behind the Twirp interface
• db: schema, SQLC configuration, generated query code, and connection setup (pg.go)
• Makefile: build commands for generating code (proto, SQLC) and running server/client
• Patterns:
• RPC layer (Twirp)
• Clean separation: transport (cmd/server) → RPC interface → business logic in internal → data layer in db
• Code generation stages: protobuf → Twirp stubs; SQL files → SQLC-generated Go code
README for additional insights
• The README documents how to generate code (make proto, SQLC runs via sqlc.yaml), start the server, start the client, and how to hit each endpoint in both Protobuf and JSON.
Elements
• Another for handwritten code (internal/twirpAPI, cmd, db/pg.go)