Skip to main content
Version: Next

🏗️ Generate OpenFeature flag manifest

warning

This feature is experimental and may change in the future.

The OpenFeature cli allow code generation for flag accessors for OpenFeature.
This allows to have a type safe way to access your flags in your code based on a flag manifest you can provide to the OpenFeature cli.

To generate the OpenFeature flag manifest you can use the generate manifest command of the go-feature-flag-cli, it will generate a flag manifest file compatible with the OpenFeature cli that you can use.

Install the Command Line

Check the installation guide to install the go-feature-flag-cli.

Generate the flag manifest

go-feature-flag-cli generate manifest \
--config="<location_of_your_flag_configuration_file>" \
--flag_manifest_destination="<destination_of_your_flag_manifest>"
paramdescription
--flag_manifest_destination(mandatory) The destination where your manifest will be stored.
--configThe location of your configuration file. (if not provided we will search a file named flags.goff.yaml in one of this directories ./, /goff/, /etc/opt/goff/.
--formatThe format of your configuration flag (acceptable values:yaml, json, toml).
Default: yaml

Example of flag manifest

flag_manifest.json
{
"flags": {
"enableFeatureA": {
"flagType": "boolean",
"defaultValue": false,
"description": "Controls whether Feature A is enabled."
},
"usernameMaxLength": {
"flagType": "integer",
"defaultValue": 50,
"description": "Maximum allowed length for usernames."
},
"greetingMessage": {
"flagType": "string",
"defaultValue": "Hello there!",
"description": "The message to use for greeting users."
}
}
}

Use the OpenFeature cli to generate the flag accessors

To install the OpenFeature cli you can follow the installation guide from the repository.

Once you have the OpenFeature cli installed you can use the generate command to generate the flag accessors.

openfeature-cli generate go \
--flag_manifest_path="<destination_of_your_flag_manifest>" \
--package_name="<name of your GO package>" \
--output_path="<destination_go_file>"

As the result of this command, you will have a file with the flag accessors generated based on the flag manifest you provided. You will be able to use a type-safe way to access your flags in your code.

info

Here the example is using code generation in GO, but react and other languages are supported.

Refer to the OpenFeature cli documentation for more information.