Getting Started
Getting Started
Section titled “Getting Started”This section walks you from a blank machine to a running go-zero service. By the end you will have Go, goctl, and (optionally) protoc installed, and you will have run your first HTTP API and RPC service.
Estimated time: ~15 minutes for the full path, or ~5 minutes for Hello World only.
Prerequisites
Section titled “Prerequisites”| Requirement | Minimum version | Notes |
|---|---|---|
| Go | 1.21 | Download |
| goctl | latest | go-zero’s code-generation CLI |
| protoc | 3.x | Required for RPC services only |
Recommended Learning Path
Section titled “Recommended Learning Path”Follow the steps in order the first time:
1. Install Go → installation/golang2. Install goctl → installation/goctl3. Install protoc → installation/protoc (RPC only)4. Configure IDE → installation/ide-plugins5. Understand API DSL → dsl/api-syntax6. Hello World → quickstart/hello-world ← start here if impatient7. Full API service → quickstart/api-service8. Full RPC service → quickstart/rpc-service60-Second Quick Start
Section titled “60-Second Quick Start”Already have Go ≥ 1.21? Run this:
# Install goctlgo install github.com/zeromicro/go-zero/tools/goctl@latest
# Scaffold and run a Hello World APIgoctl api new greetcd greetgo mod tidygo run greet.goThen in another terminal:
curl http://localhost:8888/from/you# {"message":"Hello you"}That’s it — you have a running API service. Continue to the full API quickstart to learn how to add handlers, middleware, and database access.
What goctl Generates
Section titled “What goctl Generates”Running goctl api new greet produces a complete, production-ready layout:
greet/├── etc/│ └── greet-api.yaml # configuration file├── internal/│ ├── config/ # config struct│ ├── handler/ # HTTP handlers (auto-registered)│ ├── logic/ # business logic (edit this)│ ├── middleware/ # custom middleware hooks│ ├── svc/ # service context (shared dependencies)│ └── types/ # request/response types├── greet.go # entrypoint└── greet.api # DSL sourceEdit only the files in internal/logic/. Everything else is regenerated from the .api file whenever you run goctl api go.