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.
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.
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.
A flag configuration looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|flag-key||Name of your flag.
It must be unique.
On the example the flag keys are
||Value returned by the flag if apply to the user (rule is evaluated to true) and the user is in the active percentage.|
||Value returned by the flag if apply to the user (rule is evaluated to true) and the user is not in the active percentage.|
||Value returned by the flag if not apply to the user (rule is evaluated to false).|
Percentage of the users who should be affected by the flag.
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.
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).
True if the flag is disabled.
False if you don't want to export the data in your data exporter.
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.
See rollout section for more details.
The rule format is based on the
All the operations can be written capitalized or lowercase (ex:
EQ can be used).
Logical Operations supported are
Compare Expression and their definitions (
a|b means you can use either one of the two
||not equals to|
||less than equal to|
||greater than equal to|
||in a list|
||not of a logical expression|
- Select a specific user:
key eq "firstname.lastname@example.org"
- 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.comthat have the role
backend engineerin the
proenvironment for the company
(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.
1 2 3 4 5
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:
# Flag activate only in dev rule: env == "dev"
# Flag used only in dev and staging environment rule: (env == "dev") or (env == "staging")
# Flag used on non prod environments except for the user 1234 in prod rule: (env != "prod") or (user_id == 1234)
You can have advanced configurations for your flag to have specific behavior for them, such as: