# Check goctl
which goctl && goctl --version
# Install if missing
go install github.com/zeromicro/go-zero/tools/goctl@latestCreate REST API service with goctl
mkdir -p <output_dir> && cd <output_dir>
goctl api new <service_name> --style go_zero
go mod tidy
go build ./...Create gRPC service with goctl
mkdir -p <output_dir> && cd <output_dir>
goctl rpc new <service_name> --style go_zero
go mod tidy
go build ./...Or from existing proto:
goctl rpc protoc <file>.proto --go_out=. --go-grpc_out=. --zrpc_out=. --style go_zero
go mod tidy
go build ./...Generate code from .api file
goctl api go -api <file>.api -dir . --style go_zero
go mod tidy
go build ./...Safe to re-run — won't overwrite handler/logic files with custom code.
Generate database model from table
MySQL (live DB):
goctl model mysql datasource \
-url "user:pass@tcp(host:3306)/db" \
-table "<table>" -dir ./model --style go_zeroMySQL (DDL file):
goctl model mysql ddl -src <file>.sql -dir ./model --style go_zeroWith cache: add -cache flag to any command above.
PostgreSQL:
goctl model pg datasource \
-url "postgres://user:pass@host:5432/db?sslmode=disable" \
-table "<table>" -dir ./model --style go_zeroMongoDB:
goctl model mongo -type <TypeName> -dir ./model --style go_zeroValidate .api syntax
goctl api validate -api <file>.apiUnderstand existing project structure
# List API routes
goctl api doc -dir .
# Check project file structure
find . -name "*.api" -o -name "*.proto" -o -name "*.go" | head -50See goctl-commands.md in zero-skills for config templates.
See goctl-commands.md in zero-skills for Dockerfile, Kubernetes, and Docker Compose templates.
After EVERY goctl generation:
[ ! -f go.mod ] && go mod init <module>— init module if neededgo mod tidy— resolve dependencies- Verify imports match go.mod module path
go build ./...— confirm code compiles- Check
--styleflag matches existing file naming convention