Commit 2e2ea94
committed
feat: Ignore top-level keys started with
Currently, go-feature-flag doesn't support reusable targeting conditions out of the box. So we cannot define set of rules
```yaml
my-custom-group:
- query: role eq "admin"
- query: group eq "QA"
- query: email eq "custom@example.com"
...
my-flag:
targeting:
- query: my-custom-group eq true
variation: enabled
```
But something similar can be achieved using YAML anchors. The issue with this approach is go-feature-flag treats every top-level key as a flag. So this is invalid configuration because my-custom-group is invalid flag:
```yaml
x-custom-group: &x-custom-group
- query: role eq "admin"
variation: enabled
- query: group eq "QA"
variation: enabled
- query: email eq "custom@example.com"
variation: enabled
...
my-flag:
variations:
enabled: true
disabled: false
targeting:
- *x-custom-group
defaultRule:
variation: disabled
```
It is possible to define anchors as part of the flag and then reuse it, but it lowers readability of the config file.
Usually, YAML consumers ignores keys started with `x-`. E.g. docker compose does this since 2017, openapi allows `x-` keys for extending schema since it was swagger, etc.
So this commit brings this approach into `go-feature-flag`. Now we can define top-level anchors started with `x-` and reuse these snippets to define multiple flags.
I've decided to ignore `x-` keys for JSON and TOML too. E.g. for JSON it might be used as a comment, so there is still value provided. And it is nice to be able to transparently convert flags definition between formats so they remain valid.x-
1 parent 42f2ccd commit 2e2ea94
2 files changed
Lines changed: 14 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
75 | | - | |
76 | 74 | | |
77 | 75 | | |
78 | 76 | | |
79 | 77 | | |
80 | 78 | | |
81 | 79 | | |
82 | | - | |
83 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
84 | 87 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
0 commit comments