data Flag
A feature flag with rules (§14.2): a percentage of users / nodes / tenants, allow and deny lists. on(for: p) is deterministic for
one principal: the answer depends on the flag's name and the principal only, never on time or chance.
newSearch: Flag = Flag.off // everybody off
live: Flag = Flag.percent(10, by: .Tenant) // 10 % of the tenants
beta: Flag = Flag.on // everybody onAt run time the rules change with oxl config set Limits.newSearch 25% (also on, off, percent=25,by=tenant,allow=a;b,deny=c
or the JSON object), per layer like any other value.
Example:
dynamic Features {
newSearch: Flag = Flag.percent(30)
legacy: Flag = Flag.off
}
fn main() io {
let f = Features.get()
let ann = Principal.User("ann", [], Map.new(), false, none)
// the same principal always gets the same answer
print("{f.newSearch.on(r#for: ann) == f.newSearch.on(r#for: ann)} {f.legacy.on(r#for: ann)}")
}Вывод
true false
pub(api) data FlagПотокобезопасность. a handle may be shared by tasks; the answer for a principal does not change while the rules do not.
С версии. 1.0.0-beta
Методы
percent | (p: f64, by: FlagBy, allow: List<str>, deny: List<str>) -> FlagOn for p percent (0..100) of the users (by), plus the allow list, minus the deny list. |
open | (cfg: str, key: str, default: Flag, gate: DynGate) -> FlagDeclares the flag (once per process) and returns it bound to the cluster value; called by the generated Config.get(). |
on | (r#for: &Principal) -> boolIs the flag on for p? |
current | () -> strThe rules in force (JSON). |
set | (text: str, layer: DynScope) -> () | DynErrorReplaces the rules of layer ("on", "off", "25%", "percent=25,by=tenant" or JSON). |
setAs | (p: &Principal, text: str, layer: DynScope) -> () | DynErrorset on behalf of p. |
Определено в: std/core/dynconf.oxl:719