How to 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://editor.gofeatureflag.org.
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
- JSON
- TOML
# This is your configuration for your first flag
first-flag:
variations: # All possible return value for your feature flag
A: false
B: true
targeting: # If you want to target a subset of your users in particular
- query: key eq "random-key"
percentage:
A: 0
B: 100
defaultRule: # When no targeting match we use the defaultRule
variation: A
metadata:
issue_link: https://github.com/thomaspoignant/go-feature-flag/issues/XXX
description: this is my first feature flag
# A second example of a flag configuration
second-flag:
variations:
A: "valueA"
B: "valueB"
defaultValue: "a default value"
targeting:
- name: rule1
query: key eq "not-a-key"
percentage:
A: 10
B: 90
defaultRule:
name: defaultRule
variation: defaultValue
version: "12"
experimentation:
start: 2021-03-20T00:00:00.1-05:00
end: 2021-03-21T00:00:00.1-05:00
{
"first-flag": {
"variations": {
"A": false,
"B": true
},
"targeting": [
{
"query": "key eq \"random-key\"",
"percentage": {
"A": 0,
"B": 100
}
}
],
"defaultRule": {
"variation": "A"
},
"metadata": {
"issue_link": "https://github.com/thomaspoignant/go-feature-flag/issues/XXX",
"description": "this is my first feature flag"
}
},
"second-flag": {
"variations": {
"A": "valueA",
"B": "valueB",
"defaultValue": "a default value"
},
"targeting": [
{
"name": "rule1",
"query": "key eq \"not-a-key\"",
"percentage": {
"A": 10,
"B": 90
}
}
],
"defaultRule": {
"name": "defaultRule",
"variation": "defaultValue"
},
"version": "12",
"experimentation": {
"start": "2021-03-20T05:00:00.100Z",
"end": "2021-03-21T05:00:00.100Z"
}
}
}
[first-flag.variations]
A = false
B = true
[[first-flag.targeting]]
query = 'key eq "random-key"'
[first-flag.targeting.percentage]
A = 0
B = 100
[first-flag.defaultRule]
variation = "A"
[first-flag.metadata]
issue_link = "https://github.com/thomaspoignant/go-feature-flag/issues/XXX"
description = "this is my first feature flag"
[second-flag]
version = "12"
[second-flag.variations]
A = "valueA"
B = "valueB"
defaultValue = "a default value"
[[second-flag.targeting]]
name = "rule1"
query = 'key eq "not-a-key"'
[second-flag.targeting.percentage]
A = 10
B = 90
[second-flag.defaultRule]
name = "defaultRule"
variation = "defaultValue"
[second-flag.experimentation]
start = 2021-03-20T05:00:00.100Z
end = 2021-03-21T05:00:00.100Z
Format details
Field | Description |
---|---|
flag-key | Name of your flag. It must be unique. On the example the flag keys are |
bucketing-key (optional) | Selects a key from the evaluation context that will be used in place
of the If |
variations | Variations are all the variations available for this flag. It is represented as a key/value element. The key is the name of the
variation and the value could be of any types available (
You can have as many variations as needed.
|
targeting (optional) | Targeting contains the list of rules you have to target a subset of your users. You can have as many target as needed. This field is an See rules format to have more info on how to write a rule. |
defaultRule | DefaultRule is the rule that is applied if the user does not match in any targeting. See rules format to have more info on how to write a rule. |
trackEvents (optional) |
Default: |
disable (optional) |
Default: |
version (optional) | The This string is used to display the information in the notifiers and data collection, you have to update it yourself. Default: |
metadata (optional) | This field allows adding a wealth of information about a particular feature flag, such as a configuration URL or the originating Jira issue. |
scheduledRollout (optional) |
You can add several steps that update the flag, this is typically used if you want to gradually add more user in your flag. See Scheduled rollout to have more info on how to use it. |
experimentation (optional) | Experimentation allows you to configure a start date and an end date for your flag. When the experimentation is not running, the flag will serve the default value. See Experimentation rollout to have more info on how to use it. |
Advanced configurations
You can have advanced configurations for your flag for them to have specific behavior, such as: