-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsettings.go
40 lines (34 loc) · 1.06 KB
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package settings
import (
"log"
"time"
)
type setterFunc func(string) error
type HubCacheSettings struct {
ServerCacheEnabled bool
ClientCacheEnabled *bool
Ttl *time.Duration
ClearTime time.Time
// a map of handler function which map settings key to setter functions
// for individual properties
setters map[HubSettingKey]setterFunc
}
func NewCacheSettings(clearConnectionCache func(string) error, serverCacheEnabled bool) *HubCacheSettings {
hs := &HubCacheSettings{
ServerCacheEnabled: serverCacheEnabled,
}
hs.setters = map[HubSettingKey]setterFunc{
SettingKeyCacheEnabled: hs.SetEnabled,
SettingKeyCacheTtlOverride: hs.SetTtl,
SettingKeyCacheClearTimeOverride: hs.SetClearTime,
SettingKeyConnectionCacheClear: clearConnectionCache,
}
return hs
}
func (s *HubCacheSettings) Apply(key string, jsonValue string) error {
if applySetting, found := s.setters[HubSettingKey(key)]; found {
return applySetting(jsonValue)
}
log.Println("[WARN] trying to apply unknown setting:", key, "=>", jsonValue)
return nil
}