docs/current_docs/extending/modules/state.mdx
Object state can be exposed as a Dagger Function, without having to create a getter function explicitly. Depending on the language used, this state is exposed using struct fields (Go), object attributes (Python) or object properties (TypeScript).
<Tabs groupId="language" queryString="sdk"> <TabItem value="go" label="Go">:::warning Dagger only exposes a struct's public fields; private fields will not be exposed. :::
Here's an example where one struct field is exposed as a Dagger Function, while the other is not:
Here's an example where one attribute is exposed as a Dagger Function, while the other is not:
Notice that compared to dataclasses.field, the dagger.field wrapper only supports setting init: bool, and both default and default_factory in the same default parameter.
:::note
In a future version of the Python SDK, the dagger.function decorator will be used as a descriptor in place of dagger.field to make the distinction clearer.
:::
Here's an example where one field is exposed as a Dagger Function, while the other is not:
Here's an example where one field is exposed as a Dagger Function, while the other is not:
In case of a field that shouldn't be serialized at all, this can be achieved by marking it as transient in Java.
Here's an example where one field is exposed as a Dagger Function, while the other is not:
Confirm with dagger call --help or .help my-module that only the greeting function was created, with name remaining only a constructor argument:
FUNCTIONS
greeting The greeting to use
message Return the greeting message
ARGUMENTS
--greeting string The greeting to use (default "Hello")
--name string Who to greet (default "World")