2017-08-14 23:36:22 +05:30
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2020-04-16 22:12:38 +05:30
|
|
|
"github.com/elyby/chrly/http"
|
2019-11-21 04:03:13 +05:30
|
|
|
"github.com/elyby/chrly/mojangtextures"
|
2017-08-14 23:36:22 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
type StorageFactory struct {
|
|
|
|
Config *viper.Viper
|
|
|
|
}
|
|
|
|
|
|
|
|
type RepositoriesCreator interface {
|
2020-01-02 02:12:45 +05:30
|
|
|
CreateSkinsRepository() (http.SkinsRepository, error)
|
|
|
|
CreateCapesRepository() (http.CapesRepository, error)
|
2019-11-21 04:03:13 +05:30
|
|
|
CreateMojangUuidsRepository() (mojangtextures.UuidsStorage, error)
|
2017-08-14 23:36:22 +05:30
|
|
|
}
|
|
|
|
|
2020-04-16 22:12:38 +05:30
|
|
|
// TODO: redundant
|
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{
|
2019-04-25 04:53:10 +05:30
|
|
|
BasePath: factory.Config.GetString("storage.filesystem.basePath"),
|
2017-08-14 23:36:22 +05:30
|
|
|
CapesDirName: factory.Config.GetString("storage.filesystem.capesDirName"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|