2017-08-14 23:36:22 +05:30
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2017-08-18 03:20:23 +05:30
|
|
|
"elyby/minecraft-skinsystem/interfaces"
|
2017-08-14 23:36:22 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
type StorageFactory struct {
|
|
|
|
Config *viper.Viper
|
|
|
|
}
|
|
|
|
|
|
|
|
type RepositoriesCreator interface {
|
2017-08-18 03:20:23 +05:30
|
|
|
CreateSkinsRepository() (interfaces.SkinsRepository, error)
|
|
|
|
CreateCapesRepository() (interfaces.CapesRepository, error)
|
2017-08-14 23:36:22 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func (factory *StorageFactory) CreateFactory(backend string) RepositoriesCreator {
|
|
|
|
switch backend {
|
|
|
|
case "redis":
|
|
|
|
return &RedisFactory{
|
|
|
|
Host: factory.Config.GetString("storage.redis.host"),
|
|
|
|
Port: factory.Config.GetInt("storage.redis.port"),
|
|
|
|
PoolSize: factory.Config.GetInt("storage.redis.poolSize"),
|
|
|
|
}
|
|
|
|
case "filesystem":
|
|
|
|
return &FilesystemFactory{
|
|
|
|
BasePath : factory.Config.GetString("storage.filesystem.basePath"),
|
|
|
|
CapesDirName: factory.Config.GetString("storage.filesystem.capesDirName"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|