2020-04-16 22:12:38 +05:30
|
|
|
package di
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/goava/di"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2020-04-19 05:01:09 +05:30
|
|
|
. "github.com/elyby/chrly/db"
|
2020-04-16 22:12:38 +05:30
|
|
|
"github.com/elyby/chrly/http"
|
|
|
|
"github.com/elyby/chrly/mojangtextures"
|
|
|
|
)
|
|
|
|
|
|
|
|
var db = di.Options(
|
2020-04-19 05:01:09 +05:30
|
|
|
di.Provide(newRedisFactory),
|
|
|
|
di.Provide(newFSFactory),
|
2020-04-16 22:12:38 +05:30
|
|
|
di.Provide(newSkinsRepository),
|
|
|
|
di.Provide(newCapesRepository),
|
|
|
|
di.Provide(newMojangUUIDsRepository),
|
|
|
|
di.Provide(newMojangSignedTexturesStorage),
|
|
|
|
)
|
|
|
|
|
2020-04-19 05:01:09 +05:30
|
|
|
func newRedisFactory(config *viper.Viper) *RedisFactory {
|
|
|
|
config.SetDefault("storage.redis.host", "localhost")
|
|
|
|
config.SetDefault("storage.redis.port", 6379)
|
|
|
|
config.SetDefault("storage.redis.poll", 10)
|
|
|
|
|
|
|
|
return &RedisFactory{
|
2020-04-16 22:12:38 +05:30
|
|
|
Host: config.GetString("storage.redis.host"),
|
|
|
|
Port: config.GetInt("storage.redis.port"),
|
|
|
|
PoolSize: config.GetInt("storage.redis.poolSize"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-19 05:01:09 +05:30
|
|
|
func newFSFactory(config *viper.Viper) *FilesystemFactory {
|
|
|
|
config.SetDefault("storage.filesystem.basePath", "data")
|
|
|
|
config.SetDefault("storage.filesystem.capesDirName", "capes")
|
|
|
|
|
|
|
|
return &FilesystemFactory{
|
2020-04-16 22:12:38 +05:30
|
|
|
BasePath: config.GetString("storage.filesystem.basePath"),
|
|
|
|
CapesDirName: config.GetString("storage.filesystem.capesDirName"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// v4 had the idea that it would be possible to separate backends for storing skins and capes.
|
|
|
|
// But in v5 the storage will be unified, so this is just temporary constructors before large reworking.
|
|
|
|
//
|
|
|
|
// Since there are no options for selecting target backends,
|
|
|
|
// all constants in this case point to static specific implementations.
|
|
|
|
|
2020-04-19 05:01:09 +05:30
|
|
|
func newSkinsRepository(factory *RedisFactory) (http.SkinsRepository, error) {
|
2020-04-16 22:12:38 +05:30
|
|
|
return factory.CreateSkinsRepository()
|
|
|
|
}
|
|
|
|
|
2020-04-19 05:01:09 +05:30
|
|
|
func newCapesRepository(factory *FilesystemFactory) (http.CapesRepository, error) {
|
2020-04-16 22:12:38 +05:30
|
|
|
return factory.CreateCapesRepository()
|
|
|
|
}
|
|
|
|
|
2020-04-19 05:01:09 +05:30
|
|
|
func newMojangUUIDsRepository(factory *RedisFactory) (mojangtextures.UuidsStorage, error) {
|
2020-04-16 22:12:38 +05:30
|
|
|
return factory.CreateMojangUuidsRepository()
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMojangSignedTexturesStorage() mojangtextures.TexturesStorage {
|
|
|
|
texturesStorage := mojangtextures.NewInMemoryTexturesStorage()
|
|
|
|
texturesStorage.Start()
|
|
|
|
|
|
|
|
return texturesStorage
|
|
|
|
}
|