Visibility
By default all declarations in FTL are visible only to the module they're declared in. The implicit visibility of types is that of the first verb or other declaration that references it.
Exporting declarations
Exporting a declaration makes it accessible to other modules. Some declarations that are entirely local to a module, such as secrets/config, cannot be exported.
Types that are transitively referenced by an exported declaration will be automatically exported unless they were already defined but unexported. In this case, an error will be raised and the type must be explicitly exported.
- Go
- Kotlin
- Java
- Schema
The following table describes the go directives used to export the corresponding declaration:
Symbol | Export syntax |
---|---|
Verb | //ftl:verb export |
Data | //ftl:data export |
Enum/Sum type | //ftl:enum export |
Typealias | //ftl:typealias export |
Topic | //ftl:export 1 |
//ftl:verb export
func Verb(ctx context.Context, in In) (Out, error)
//ftl:typealias export
type UserID string
For Kotlin the @Export
annotation can be used to export a declaration:
@Verb
@Export
fun time(): TimeResponse {
// ...
}
For Java the @Export
annotation can be used to export a declaration:
@Verb
@Export
TimeResponse time() {
// ...
}
In the FTL schema, exported declarations are prefixed with the export
keyword:
module example {
export data TimeResponse {
time Time
}
export verb time(Unit) example.TimeResponse
export topic events example.Event
export typealias UserID String
}
Non-exported declarations are visible only within their module:
module example {
data InternalConfig {
setting String
}
verb internalProcess(example.InternalConfig) Unit
}
Footnotes
-
By default, topics do not require any annotations as the declaration itself is sufficient. ↩