33 lines
1.2 KiB
Go
33 lines
1.2 KiB
Go
|
package model
|
||
|
|
||
|
// Experiments are optional functionality that can be enabled/disabled by an application either completely or individually.
|
||
|
// examples of experiments include File Sharing, Profile Images and Groups.
|
||
|
type Experiments struct {
|
||
|
enabled bool
|
||
|
experiments map[string]bool
|
||
|
}
|
||
|
|
||
|
// InitExperiments encapsulates a set of experiments separate from their storage in GlobalSettings.
|
||
|
func InitExperiments(enabled bool, experiments map[string]bool) Experiments {
|
||
|
return Experiments{
|
||
|
enabled: enabled,
|
||
|
experiments: experiments,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// IsEnabled is a convenience function that takes in an experiment and returns true if it is enabled. Experiments
|
||
|
// are only enabled if both global experiments are turned on and if the specific experiment is also turned on.
|
||
|
// The one exception to this is experiments that have been promoted to default functionality which may be turned on
|
||
|
// even if experiments turned off globally. These experiments are defined by DefaultEnabledFunctionality.
|
||
|
func (e *Experiments) IsEnabled(experiment string) bool {
|
||
|
if !e.enabled {
|
||
|
// todo handle default-enabled functionality
|
||
|
return false
|
||
|
}
|
||
|
enabled, exists := e.experiments[experiment]
|
||
|
if !exists {
|
||
|
return false
|
||
|
}
|
||
|
return enabled
|
||
|
}
|