|
|
@ -93,13 +93,13 @@ func GetSettingNoCache(key string) (*Setting, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetSetting returns the setting value via the key
|
|
|
|
// GetSetting returns the setting value via the key
|
|
|
|
func GetSetting(key string) (*Setting, error) { |
|
|
|
func GetSetting(key string) (string, error) { |
|
|
|
return cache.Get(genSettingCacheKey(key), func() (*Setting, error) { |
|
|
|
return cache.GetString(genSettingCacheKey(key), func() (string, error) { |
|
|
|
res, err := GetSettingNoCache(key) |
|
|
|
res, err := GetSettingNoCache(key) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return "", err |
|
|
|
} |
|
|
|
} |
|
|
|
return res, nil |
|
|
|
return res.SettingValue, nil |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -107,7 +107,8 @@ func GetSetting(key string) (*Setting, error) { |
|
|
|
// none existing keys and errors are ignored and result in false
|
|
|
|
// none existing keys and errors are ignored and result in false
|
|
|
|
func GetSettingBool(key string) bool { |
|
|
|
func GetSettingBool(key string) bool { |
|
|
|
s, _ := GetSetting(key) |
|
|
|
s, _ := GetSetting(key) |
|
|
|
return s.GetValueBool() |
|
|
|
v, _ := strconv.ParseBool(s) |
|
|
|
|
|
|
|
return v |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetSettings returns specific settings
|
|
|
|
// GetSettings returns specific settings
|
|
|
@ -184,8 +185,8 @@ func SetSettingNoVersion(key, value string) error { |
|
|
|
|
|
|
|
|
|
|
|
// SetSetting updates a users' setting for a specific key
|
|
|
|
// SetSetting updates a users' setting for a specific key
|
|
|
|
func SetSetting(setting *Setting) error { |
|
|
|
func SetSetting(setting *Setting) error { |
|
|
|
_, err := cache.Set(genSettingCacheKey(setting.SettingKey), func() (*Setting, error) { |
|
|
|
_, err := cache.GetString(genSettingCacheKey(setting.SettingKey), func() (string, error) { |
|
|
|
return setting, upsertSettingValue(strings.ToLower(setting.SettingKey), setting.SettingValue, setting.Version) |
|
|
|
return setting.SettingValue, upsertSettingValue(strings.ToLower(setting.SettingKey), setting.SettingValue, setting.Version) |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|