For the complete documentation index, see llms.txt. This page is also available as Markdown.

Boilerplate Code Generation

Boilerplate Generator for Ergo Framework Projects

The ergo tool generates the initial structure and source code for Ergo Framework projects. Instead of writing actor definitions, supervisor specs, and application boilerplate by hand, you describe what you want and the tool writes it for you.

The generated code is plain Go that you own and can modify freely. The tool understands which parts are structural wiring (regenerated as the project grows) and which parts are your business logic (never touched again).

Installation

Requires Go 1.21 or higher.

go install ergo.tools/ergo@latest

Quick Start

Three commands to get a running Ergo node:

ergo init MyNode github.com/myorg/mynode
cd mynode
go run ./cmd

The node starts immediately with an application, a supervisor and an actor, all wired together.

How It Works

The tool maintains ergo.yaml in the project root. This file describes the supervision tree. Every ergo add command updates this file and regenerates the affected code.

Each component produces two files:

File
Owned by
Regenerated
Contains

name_gen.go

tool

on every ergo add or ergo generate

factory, Init spec, Load group

name.go

you

never

Tune, handlers, Start, Terminate

User-owned files provide hooks that the generated code calls. The pattern is consistent across all component types:

File
Hook
Purpose

mysup.go

Tune(spec, args) (SupervisorSpec, error)

adjust supervisor spec before start

myapp.go

Tune(spec, args) (ApplicationSpec, error)

adjust application spec before start

messages.go

extraMessages() []any

register custom EDF message types

cmd/main.go

extraApps() []ApplicationBehavior

add external applications

Commands

ergo init

Creates a new project. The directory name is derived from the last segment of the module path. Generates ergo.yaml, all boilerplate, go.mod, and runs go mod tidy.

The default project has one application, one supervisor and one actor, enough to verify everything works before adding real components.

ergo add actor

Adds an actor. Parent is the name of an existing supervisor or application. Without a parent the actor is added to node.processes and spawned directly by the node at startup.

--pool generates a pool actor with a companion worker type. A pool distributes incoming messages across a fixed set of workers and restarts them on failure.

ergo add supervisor

Adds a supervisor. Parent is an existing application or supervisor.

The name comes first, and that is not stylistic: add supervisor, add app and add message each read the name from the first argument and look for flags only after it. Lead with a flag and the flag becomes the name - ergo add supervisor --type one_for_one Sup records a supervisor literally called --type, which then fails during generation. Only add actor accepts either order.

--type controls which children are restarted when one fails:

Type
Behavior

one_for_one (default)

only the failed child

all_for_one

all children

rest_for_one

the failed child and all children started after it

simple_one_for_one

many instances of one declared spec, spawned at runtime with StartChild

A supervisor of any type still needs at least one declared child: Init rejects an empty Children list with "children list can not be empty". A freshly generated supervisor has none, so add a child to it - ergo add actor MySup:Worker - before running the node. This bites hardest with simple_one_for_one, where it is tempting to assume the instances alone are enough.

--strategy controls when a child is restarted:

Strategy
Behavior

transient (default)

only on abnormal exit

permanent

always

temporary

never

ergo add app

Adds an application. --mode declares what happens to the application when one of its group members terminates. It has nothing to do with stopping the node:

Mode
Behavior

transient (default)

the application stops if a member exits abnormally

permanent

the application stops when any member exits, with that member's reason

temporary

the application stops once the last member is gone, with reason normal

A stopped application returns to ApplicationStateLoaded and the node keeps running. See Applications for the full lifecycle.

ergo add message

Adds an EDF message type. Field types can be standard Go types (string, int, bool, []byte) or framework types (gen.Alias, gen.PID, gen.Ref).

Generated struct definitions and EDF registration go into messages_gen.go, which is always regenerated when the message list changes.

If a message type has fields of other custom types, add the inner type first. EDF requires nested types to be registered before the types that reference them:

Both nodes must register the same types with identical field definitions. The registration order between nodes does not need to match; nodes negotiate numeric type IDs during handshake.

For detailed coverage of EDF, type constraints, and custom marshaling, see Network Transparency.

ergo generate

Regenerates all *_gen.go files from ergo.yaml. Your .go files are never overwritten. Searches for ergo.yaml in the current directory and its parents.

Project Structure

After ergo init MyNode github.com/myorg/mynode:

The README.md is regenerated on every ergo add or ergo generate and shows the current supervision tree.

ergo.yaml Reference

Known loggers: colored (docs), rotate (docs).

Known applications: observer (docs), radar (docs).

Customizing Generated Code

Supervisor

mynodesup.go contains Tune, called from the generated Init. The generated Init builds SupervisorSpec from ergo.yaml and passes it to Tune. Override restart parameters or add dynamic children here:

Do not replace spec.Children in Tune unless you have a specific reason. The children list is populated from ergo.yaml by the generated Init.

Application

mynodeapp.go contains Tune, called from the generated Load. The Group in Load is populated from ergo.yaml. Use Tune to set metadata, environment variables or dependencies:

Custom EDF Message Types

messages.go contains extraMessages(), called from the generated init(). Add custom types that are not declared in ergo.yaml:

For types with unexported fields or special encoding needs, implement edf.Marshaler/Unmarshaler or encoding.BinaryMarshaler/Unmarshaler in a separate file. See Network Transparency.

External Applications

Some applications cannot be described in ergo.yaml because their constructor requires runtime arguments. Add them in cmd/main.go, which is never regenerated:

Typical Workflow

Each ergo add updates ergo.yaml, regenerates *_gen.go files, and leaves your .go files untouched.

What's Next

  • Observer: web UI, API and MCP surface for inspecting running nodes and processes

  • Actors: actor types, supervision and messaging patterns

  • Applications: application lifecycle and modes

  • Pool: distributing work across worker processes

  • Network Transparency: EDF serialization and distributed messaging

Last updated

Was this helpful?