Project: GO Feature Flag (Observability and Analysis / Feature Flagging)
File: flag_format.md

sidebar_position: 30 `go-feature-flag` core feature is to centralize all your feature flags in a source file, and to avoid hosting and maintaining a backend server to manage them. Your file must be a valid `YAML`, `JSON` or `TOML` file with a list of flags *(examples: , , )*. The easiest way to create your configuration file is to used . If you prefer to do it manually please follow instruction bellow. Creating the first version of the flag is not always pleasant, that's why we have created a simple editor to create your files. A flag configuration looks like: ``` yaml test-flag: percentage: 100 rule: key eq "random-key" true: true false: false default: false disable: false trackEvents: true version: 1 rollout: experimentation: start: 2021-03-20T00:00:00.10-05:00 end: 2021-03-21T00:00:00.10-05:00 test-flag2: rule: key eq "not-a-key" percentage: 100 true: true false: false default: false version: 12 ``` ``` json { "test-flag": { "percentage": 100, "rule": "key eq \"random-key\"", "true": true, "false": false, "default": false, "disable": false, "trackEvents": true, "version": 1, "rollout": { "experimentation": { "start": "2021-03-20T05:00:00.100Z", "end": "2021-03-21T05:00:00.100Z" } } }, "test-flag2": { "rule": "key eq \"not-a-key\"", "percentage": 100, "true": true, "false": false, "default": false, "version": 12 } } ``` ``` toml [test-flag] percentage = 100.0 rule = "key eq \"random-key\"" true = true false = false default = false disable = false trackEvents = true version = 1.0 [test-flag.rollout] [test-flag.rollout.experimentation] start = 2021-03-20T05:00:00.100Z end = 2021-03-21T05:00:00.100Z [test-flag2] rule = "key eq \"not-a-key\"" percentage = 100.0 true = true false = false default = false version = 12.0 ``` | Field | Description | |:-:|--| | flag-key | Name of your flag.<br/> It must be unique.<br/>On the example the flag keys are `test-flag` and `test-flag2`. | | `true` | Value returned by the flag if apply to the user (rule is evaluated to true) and the user is in the active percentage. | | `false` | Value returned by the flag if apply to the user (rule is evaluated to true) and the user is not in the active percentage. | | `default` | Value returned by the flag if not apply to the user (rule is evaluated to false). | | `percentage` | (optional)<br/>Percentage of the users who should be affected by the flag.<br/>Default: 0<br/><br/>The percentage is computed by calculating a hash of the user key (100000 variations), it means that you can have 3 numbers after the comma. | | `rule` | (optional)<br/>Condition to determine on which user the flag should be

format is described in the .<br/>If no rule is set, the flag applies to all users *(percentage still apply)*. | | `disable` | (optional)<br/>True if the flag is disabled.<br/>Default: `false` | | `trackEvents` | (optional)<br/>False if you don't want to export the data in your data exporter.<br/>Default: `true` | | `version` | (optional)<br/>The version is the version of your flag.<br/>This number is used to display the information in the notifiers and data collection, you have to update it your self.<br/>Default: 0 | | `rollout` | (optional)<br/><code>rollout</code> contains a specific rollout strategy you want to use.<br/>See for more details. | The rule format is based on the library. All the operations can be written capitalized or lowercase (ex: `eq` or `EQ` can be used). Logical Operations supported are `AND` `OR`. Compare Expression and their definitions (`a|b` means you can use either one of the two `a` or `b`): | Operator | Description | |:-:|--| | `eq`, `==` | equals to | | `ne`, `!=` | not equals to | | `lt`, `<` | less than | | `gt`, `>` | greater than | | `le`, `<=` | less than equal to | | `ge`, `>=` | greater than equal to | | `co` | contains | | `sw` | starts with | | `ew` | ends with | | `in` | in a list | | `pr` | present | | `not` | not of a logical expression | Select a specific user: `key eq "example@example.com"` Select all identified users: `anonymous ne true` Select a user with a custom property: `userId eq "12345"` Select on multiple criteria: *All users with ids finishing by `@test.com` that have the role `backend engineer` in the `pro` environment for the company `go-feature-flag`* ```bash (key ew "@test.com") and (role eq "backend engineer") and (env eq "pro") and (company eq "go-feature-flag")` ``` When you initialise `go-feature-flag` you can set an environment for the instance of this SDK. ```go linenums="1" ffclient.Init(ffclient.Config{ // ... Environment: "prod", // ... }) ``` When an environment is set, it adds a new field in your user called `env` that you can use in your rules. It means that you can decide to activate a flag only for some environment. Example of rules based on the environment: ```yaml rule: env == "dev" ``` ```yaml rule: (env == "dev") or (env == "staging") ``` ```yaml rule: (env != "prod") or (user_id == 1234) ``` You can have advanced configurations for your flag to have specific behavior for them, such as: