Skip to main content
Version: v1.5.1

How to target specific users

Rule format

A rule is a configuration that allows to serve a variation based on some conditions.

Format details

FieldDescription
name
(optional)
Name of your rule.
This is needed when your are updating a rule using a scheduled rollout.
query

Query represents an antlr query in the nikunjy/rules format.
This field is mandatory in every rule used in the targeting field.

See query format to have the syntax.

Note: if you use the field query in a defaultRule it will be ignored.

variation
(optional)
Name of the variation to return.
percentage
(optional)

Represents the percentage we should give to each variation.

percentage:
variationA: 10.59
variationB: 9.41
variationC: 80

The format is the name of the variation and the percentage for this one.

Note: if your total is not equals to 100% this rule will be considered as invalid.

progressiveRollout
(optional)

Allow to ramp up the percentage of your flag over time.

You can decide at which percentage you starts with and at what percentage you ends with in your release ramp. Before the start date we will serve the initial percentage and, after we will serve the end percentage.

See progressive rollout to have more info on how to use it.

disable
(optional)

Set to true if you want to disable the rule.

Default: true.

info

variation, percentage and progressiveRollout are optional but you must have one of the 3.

If you have more than one field we will use the first one in that order progressiveRollout > percentage > variation.

Query 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")

Environments

When you initialise go-feature-flag you can set an environment for the instance of this SDK.

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:

# 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)

Get the latest GO Feature Flag updates