Add configuration of the storage backend

Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
kolaente 2020-10-04 22:53:49 +02:00
parent e9e3445397
commit 0ed3484457
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 13 additions and 1 deletions

View File

@ -124,6 +124,8 @@ const (
BackgroundsUnsplashEnabled Key = `backgrounds.providers.unsplash.enabled`
BackgroundsUnsplashAccessToken Key = `backgrounds.providers.unsplash.accesstoken`
BackgroundsUnsplashApplicationID Key = `backgrounds.providers.unsplash.applicationid`
KeyvalueType Key = `keyvalue.type`
)
// GetString returns a string config value
@ -277,6 +279,8 @@ func InitDefaultConfig() {
BackgroundsEnabled.setDefault(true)
BackgroundsUploadEnabled.setDefault(true)
BackgroundsUnsplashEnabled.setDefault(false)
// Key Value
KeyvalueType.setDefault("memory")
}
// InitConfig initializes the config, sets defaults etc.

View File

@ -18,7 +18,9 @@
package keyvalue
import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/modules/keyvalue/memory"
"code.vikunja.io/api/pkg/modules/keyvalue/redis"
)
// Storage defines an interface for saving key-value pairs
@ -32,7 +34,13 @@ var store Storage
// InitStorage initializes the configured storage backend
func InitStorage() {
store = memory.NewStorage()
switch config.KeyvalueType.GetString() {
case "redis":
store = redis.NewStorage()
case "memory":
default:
store = memory.NewStorage()
}
}
// Put puts a value in the storage backend