Skip to content

Project Creation Methods

goctl provides several ways to create projects depending on your starting point.

The fastest way to start a brand-new service:

Terminal window
# HTTP API service
goctl api new myservice
cd myservice && go mod tidy
# gRPC service
goctl rpc new myservice
cd myservice && go mod tidy

goctl creates a working project with a sample .api / .proto file, entrypoint, config, and a stub logic layer.

When you already have a .api or .proto file (e.g. shared across teams):

Terminal window
# From .api file
mkdir myservice && cd myservice
go mod init myservice
goctl api go -api myservice.api -dir .
go mod tidy
# From .proto file
mkdir myservice && cd myservice
go mod init myservice
goctl rpc protoc myservice.proto \
--go_out=./pb \
--go-grpc_out=./pb \
--zrpc_out=.
go mod tidy

Use this approach when the DSL is the source of truth checked into a separate repo.

After editing the .api or .proto file, regenerate without overwriting your logic:

Terminal window
# API: re-runs generation, preserves internal/logic/
goctl api go -api myservice.api -dir .
# RPC: re-runs generation, preserves internal/logic/
goctl rpc protoc myservice.proto \
--go_out=./pb \
--go-grpc_out=./pb \
--zrpc_out=.

goctl never writes to internal/logic/. Everything else (handlers, routes, types, config structs) is regenerated.

For teams that want to enforce conventions (logging setup, error codes, CI config), goctl supports custom templates:

~/.goctl/
# Init the default template directory
goctl template init
# Edit a template, e.g. the logic file template
vim ~/.goctl/api/logic.tpl
# Use the templates next time you generate
goctl api go -api myservice.api -dir .

The template directory mirrors the generated output structure. Common customizations:

  • Add standard error code imports
  • Inject team-specific logging calls
  • Add OpenTelemetry span creation

goctl can also generate non-Go artifacts:

Terminal window
# Dockerfile
goctl docker -go main.go
# Kubernetes deployment + service manifests
goctl kube deploy \
-name myservice \
-namespace prod \
-image myregistry/myservice:v1.0.0 \
-o deployment.yaml
# DB model layer from SQL DDL
goctl model mysql ddl \
-src schema.sql \
-dir internal/model
# Client SDKs
goctl api ts -api myservice.api -dir ./sdk/ts
goctl api dart -api myservice.api -dir ./sdk/dart
MethodWhen to use
goctl api new / rpc newStarting a new service from zero
goctl api go / rpc protocDSL file already exists
RegenerationAfter editing .api or .proto
Custom templatesEnforcing team-level conventions
goctl docker / kubeGenerating deployment artifacts