Documentation
¶
Overview ¶
Package featureflag 提供本地评估的特性开关与 A/B 实验: 布尔开关、百分比灰度、按属性定向、多变体实验,均基于确定性哈希分桶, 同一标识(如 userID)多次评估结果稳定,无需远程调用。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attributes ¶
Attributes 是用于定向匹配的标识属性(如 {"country":"CN","plan":"pro"})。
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine 持有开关与实验配置,提供线程安全的评估。
func (*Engine) IsEnabled ¶
func (e *Engine) IsEnabled(key, id string, attrs Attributes) bool
IsEnabled 评估某标识 id 是否命中开关 key。attrs 可为 nil。 评估顺序:定向规则(首个命中)→ 总开关 → 百分比灰度(按 id 稳定分桶)。
func (*Engine) SetExperiment ¶
func (e *Engine) SetExperiment(x Experiment)
SetExperiment 注册/更新一个实验。
type Experiment ¶
type Experiment struct {
Key string
Variants []string // 变体名,如 ["control","treatment"]
Weights []float64 // 各变体权重,缺省或非法时等分;和应约等于 1
Coverage float64 // 0~1 参与实验的比例,0 表示用默认 1
}
Experiment 是一个 A/B(/n) 实验定义。
Click to show internal directories.
Click to hide internal directories.