Skip to main content

Verbs

Defining Verbs

To declare a Verb, write a normal Go function with the following signature, annotated with the Go comment directive //ftl:verb:

//ftl:verb
func F(context.Context, In) (Out, error) { }

eg.

type EchoRequest struct {}

type EchoResponse struct {}

//ftl:verb
func Echo(ctx context.Context, in EchoRequest) (EchoResponse, error) {
// ...
}

By default verbs are only visible to other verbs in the same module (see visibility for more information).

Calling Verbs

To call a verb, import the module's verb client ({ModuleName}.{VerbName}Client), add it to your verb's signature, then invoke it as a function. eg.

//ftl:verb
func Echo(ctx context.Context, in EchoRequest, tc time.TimeClient) (EchoResponse, error) {
out, err := tc(ctx, TimeRequest{...})
}

Verb clients are generated by FTL. If the callee verb belongs to the same module as the caller, you must build the module first (with callee verb defined) in order to generate its client for use by the caller. Local verb clients are available in the generated types.ftl.go file as {VerbName}Client.