Skip to main content
Version: v0.22.3

Configure a flag

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: YAML, JSON, TOML).

The easiest way to create your configuration file is to used GO Feature Flag Editor available at https://thomaspoignant.github.io/go-feature-flag-editor/.
If you prefer to do it manually please follow instruction bellow.

Editor

Creating the first version of the flag is not always pleasant, that's why we have created GO Feature Flag Editor a simple editor to create your files.

Example

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

Format details

FieldDescription
flag-keyName of your flag.
It must be unique.
On the example the flag keys are test-flag and test-flag2.
trueValue returned by the flag if apply to the user (rule is evaluated to true) and the user is in the active percentage.
falseValue returned by the flag if apply to the user (rule is evaluated to true) and the user is not in the active percentage.
defaultValue returned by the flag if not apply to the user (rule is evaluated to false).
percentage(optional)
Percentage of the users who should be affected by the flag.
Default: 0

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)
Condition to determine on which user the flag should be applied.
Rule format is described in the rule format section.
If no rule is set, the flag applies to all users (percentage still apply).
disable(optional)
True if the flag is disabled.
Default: false
trackEvents(optional)
False if you don't want to export the data in your data exporter.
Default: true
version(optional)
The version is the version of your flag.
This number is used to display the information in the notifiers and data collection, you have to update it your self.
Default: 0
rollout(optional)
rollout contains a specific rollout strategy you want to use.
See rollout section for more details.

Rule format

The rule format is based on the nikunjy/rules 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):

OperatorDescription
eq | ==equals to
ne | !=not equals to
lt | <less than
gt | >greater than
le | <=less than equal to
ge | >=greater than equal to
cocontains
swstarts with
ewends with
inin a list
prpresent
notnot of a logical expression

Examples

  • 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
    (key ew "@test.com") and (role eq "backend engineer") and (env eq "pro") and (company eq "go-feature-flag")`

Advanced configurations

You can have advanced configurations for your flag to have specific behavior for them, such as:

Get the latest GO Feature Flag updates