Fix Map Panic

This commit is contained in:
Sarah Jamie Lewis 2023-02-25 07:19:12 -08:00
parent 0e49d70d65
commit 195e048410
1 changed files with 7 additions and 0 deletions

View File

@ -1,10 +1,13 @@
package model
import "sync"
// 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
lock sync.Mutex
}
// InitExperiments encapsulates a set of experiments separate from their storage in GlobalSettings.
@ -24,6 +27,10 @@ func (e *Experiments) IsEnabled(experiment string) bool {
// todo handle default-enabled functionality
return false
}
// go will sometimes panic if we do not lock this read-only map...
e.lock.Lock()
defer e.lock.Unlock()
enabled, exists := e.experiments[experiment]
if !exists {
return false