Install goctl
Install goctl
Section titled “Install goctl”goctl (pronounced “go control”) is go-zero’s code-generation CLI. It reads .api and .proto files and produces complete, production-ready Go services — eliminating boilerplate.
Install
Section titled “Install”go install github.com/zeromicro/go-zero/tools/goctl@latestVerify
Section titled “Verify”goctl --version# goctl version 1.7.3 darwin/arm64If you see command not found, your $GOBIN is not in PATH. Fix it:
# Add to ~/.zshrc or ~/.bashrcexport GOBIN=$(go env GOPATH)/binexport PATH=$PATH:$GOBINsource ~/.zshrcUpgrade
Section titled “Upgrade”Re-run the same install command to get the latest version:
go install github.com/zeromicro/go-zero/tools/goctl@latestgoctl --versionWhat goctl Can Generate
Section titled “What goctl Can Generate”| Command | Output |
|---|---|
goctl api new <name> | Complete HTTP API service skeleton |
goctl api go -api f.api -dir . | Go code from an existing .api file |
goctl rpc new <name> | Complete gRPC service skeleton |
goctl rpc protoc f.proto ... | Go code from an existing .proto file |
goctl model mysql ddl -src f.sql -dir . | DB model layer from SQL schema |
goctl docker -go main.go | Dockerfile |
goctl kube deploy ... | Kubernetes deployment manifest |
Next Step
Section titled “Next Step”For RPC services: Install protoc →
For HTTP-only services: Hello World →