When you run goa gen
, Goa follows a systematic process to transform your
design into working code:
Goa first creates and runs a temporary program:
During this phase, Goa creates a temporary main.go
program that:
This temporary program serves as the entry point for transforming your design into code. It’s automatically created and removed during the generation process, so you never need to manage it directly.
During this phase, Goa loads and evaluates your design package:
This evaluation phase is critical as it transforms your declarative design into a structured model that can be used for code generation.
Once the expressions have been validated, they are passed to Goa’s code
generators. The generators use these expressions as input data to render various
code templates. They generate transport-specific code for HTTP and gRPC, create
all necessary supporting files, and write the complete output to the gen/
directory. This generation step produces all the code needed to run your service
while maintaining consistency across the codebase.
A typical generated project structure:
myservice/
├── cmd/ # Generated example commands
│ └── calc/
│ ├── grpc.go
│ └── http.go
├── design/ # Your design files
│ └── design.go
├── gen/ # Generated code
│ ├── calc/ # Service-specific code
│ │ ├── client/
│ │ ├── endpoints/
│ │ └── service/
│ └── http/ # Transport layer
│ ├── client/
│ └── server/
└── myservice.go # Generated service implementation stub
Consult the Generated Code section for more details on the generated code.