mirror of
https://github.com/elyby/chrly.git
synced 2025-05-31 14:11:51 +05:30
Попытка сделать фабрики репозиториев для абстрактных хранилищ данных.
Добавлено чтение конфигурации из файла.
This commit is contained in:
34
db/factory.go
Normal file
34
db/factory.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"elyby/minecraft-skinsystem/repositories"
|
||||
)
|
||||
|
||||
type StorageFactory struct {
|
||||
Config *viper.Viper
|
||||
}
|
||||
|
||||
type RepositoriesCreator interface {
|
||||
CreateSkinsRepository() (repositories.SkinsRepository, error)
|
||||
CreateCapesRepository() (repositories.CapesRepository, error)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user