Skip to content

Commit 3b08ee5

Browse files
Adding section in the documentation to explain environments (#255)
* Adding section in the documentation to explain environments * change order pages
1 parent a0a75c2 commit 3b08ee5

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

docs/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ During the initialization you must give a [`ffclient.Config{}`](https://pkg.go.d
1010
|---|---|
1111
|`Retriever` | The configuration retriever you want to use to get your flag file<br> *See [Store your flag file](flag_file/index.md) for the configuration details*.|
1212
|`Context` | *(optional)*<br>The context used by the retriever.<br />Default: `context.Background()`|
13-
|`Environment` | *(optional)*<br>The environment the app is running under, can be checked in feature flag rules.<br />Default: `""`|
13+
|`Environment` | <a name="option_environment"></a>*(optional)*<br>The environment the app is running under, can be checked in feature flag rules.<br />Default: `""`<br>*Check [**"environments"** section](../flag_format/#environments) to understand how to use this parameter.*|
1414
|`DataExporter` | *(optional)*<br>DataExporter defines how to export data on how your flags are used.<br> *see [export data section](data_collection/index.md) for more details*.|
1515
|`FileFormat`| *(optional)*<br>Format of your configuration file. Available formats are `yaml`, `toml` and `json`, if you omit the field it will try to unmarshal the file as a `yaml` file.<br>Default: `YAML`|
1616
|`Logger` | *(optional)*<br>Logger used to log what `go-feature-flag` is doing.<br />If no logger is provided the module will not log anything.<br>Default: No log|

docs/flag_format.md

+29
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,35 @@ Compare Expression and their definitions (`a|b` means you can use either one of
148148
(key ew "@test.com") and (role eq "backend engineer") and (env eq "pro") and (company eq "go-feature-flag")`
149149
```
150150

151+
## Environments
152+
153+
When you initialise `go-feature-flag` you can set an [environment](../configuration/#option_environment) for the instance of this SDK.
154+
155+
```go linenums="1"
156+
ffclient.Init(ffclient.Config{
157+
// ...
158+
Environment: "prod",
159+
// ...
160+
})
161+
```
162+
163+
When an environment is set, it adds a new field in your user called **`env`** that you can use in your rules.
164+
It means that you can decide to activate a flag only for some **environment**.
165+
166+
**Example of rules based on the environment:**
167+
```yaml
168+
# Flag activate only in dev
169+
rule: env == "dev"
170+
```
171+
```yaml
172+
# Flag used only in dev and staging environment
173+
rule: (env == "dev") or (env == "staging")
174+
```
175+
```yaml
176+
# Flag used on non prod environments except for the user 1234 in prod
177+
rule: (env != "prod") or (user_id == 1234)
178+
```
179+
151180
## Advanced configurations
152181

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

mkdocs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ nav:
5656
- 'Home': 'index.md'
5757
- 'quickstart.md'
5858
- 'configuration.md'
59+
- 'flag_format.md'
5960
- 'Store your flag file':
6061
- 'flag_file/index.md'
6162
- 'flag_file/s3.md'
@@ -65,7 +66,6 @@ nav:
6566
- 'flag_file/google_cloud_storage.md'
6667
- 'flag_file/kubernetes_configmaps.md'
6768
- 'flag_file/custom.md'
68-
- 'flag_format.md'
6969
- 'users.md'
7070
- 'Rollout strategies':
7171
- 'rollout/index.md'

0 commit comments

Comments
 (0)