From b1dbee2310e15e7ca0d47c1f761ae2f285728838 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 18 Aug 2017 00:50:23 +0300 Subject: [PATCH] =?UTF-8?q?repositories=20package=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B2?= =?UTF-8?q?=20interfaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- daemon/http.go | 10 +++++----- db/factory.go | 6 +++--- db/filesystem.go | 6 +++--- db/redis.go | 6 +++--- repositories/skins.go => interfaces/repositories.go | 10 ++++++++-- repositories/capes.go | 7 ------- ui/service.go | 12 ++++++------ worker/worker.go | 4 ++-- 8 files changed, 30 insertions(+), 31 deletions(-) rename repositories/skins.go => interfaces/repositories.go (51%) delete mode 100644 repositories/capes.go diff --git a/daemon/http.go b/daemon/http.go index 60bb15b..bee888c 100644 --- a/daemon/http.go +++ b/daemon/http.go @@ -9,17 +9,17 @@ import ( "github.com/mono83/slf/wd" - "elyby/minecraft-skinsystem/repositories" + "elyby/minecraft-skinsystem/interfaces" "elyby/minecraft-skinsystem/ui" ) type Config struct { ListenSpec string - SkinsRepo repositories.SkinsRepository - CapesRepo repositories.CapesRepository - Logger wd.Watchdog - UI ui.Config + SkinsRepo interfaces.SkinsRepository + CapesRepo interfaces.CapesRepository + Logger wd.Watchdog + UI ui.Config } func Run(cfg *Config) error { diff --git a/db/factory.go b/db/factory.go index 5c2eb33..62eaba5 100644 --- a/db/factory.go +++ b/db/factory.go @@ -3,7 +3,7 @@ package db import ( "github.com/spf13/viper" - "elyby/minecraft-skinsystem/repositories" + "elyby/minecraft-skinsystem/interfaces" ) type StorageFactory struct { @@ -11,8 +11,8 @@ type StorageFactory struct { } type RepositoriesCreator interface { - CreateSkinsRepository() (repositories.SkinsRepository, error) - CreateCapesRepository() (repositories.CapesRepository, error) + CreateSkinsRepository() (interfaces.SkinsRepository, error) + CreateCapesRepository() (interfaces.CapesRepository, error) } func (factory *StorageFactory) CreateFactory(backend string) RepositoriesCreator { diff --git a/db/filesystem.go b/db/filesystem.go index 3fb2f03..d8dfc01 100644 --- a/db/filesystem.go +++ b/db/filesystem.go @@ -6,7 +6,7 @@ import ( "strings" "elyby/minecraft-skinsystem/model" - "elyby/minecraft-skinsystem/repositories" + "elyby/minecraft-skinsystem/interfaces" ) type FilesystemFactory struct { @@ -14,11 +14,11 @@ type FilesystemFactory struct { CapesDirName string } -func (f FilesystemFactory) CreateSkinsRepository() (repositories.SkinsRepository, error) { +func (f FilesystemFactory) CreateSkinsRepository() (interfaces.SkinsRepository, error) { panic("skins repository not supported for this storage type") } -func (f FilesystemFactory) CreateCapesRepository() (repositories.CapesRepository, error) { +func (f FilesystemFactory) CreateCapesRepository() (interfaces.CapesRepository, error) { if err := f.validateFactoryConfig(); err != nil { return nil, err } diff --git a/db/redis.go b/db/redis.go index 3c74675..da09a87 100644 --- a/db/redis.go +++ b/db/redis.go @@ -15,7 +15,7 @@ import ( "github.com/mediocregopher/radix.v2/util" "elyby/minecraft-skinsystem/model" - "elyby/minecraft-skinsystem/repositories" + "elyby/minecraft-skinsystem/interfaces" ) type RedisFactory struct { @@ -25,7 +25,7 @@ type RedisFactory struct { connection util.Cmder } -func (f RedisFactory) CreateSkinsRepository() (repositories.SkinsRepository, error) { +func (f RedisFactory) CreateSkinsRepository() (interfaces.SkinsRepository, error) { connection, err := f.getConnection() if err != nil { return nil, err @@ -34,7 +34,7 @@ func (f RedisFactory) CreateSkinsRepository() (repositories.SkinsRepository, err return &redisDb{connection}, nil } -func (f RedisFactory) CreateCapesRepository() (repositories.CapesRepository, error) { +func (f RedisFactory) CreateCapesRepository() (interfaces.CapesRepository, error) { panic("capes repository not supported for this storage type") } diff --git a/repositories/skins.go b/interfaces/repositories.go similarity index 51% rename from repositories/skins.go rename to interfaces/repositories.go index c5b96fb..e8b5695 100644 --- a/repositories/skins.go +++ b/interfaces/repositories.go @@ -1,9 +1,15 @@ -package repositories +package interfaces -import "elyby/minecraft-skinsystem/model" +import ( + "elyby/minecraft-skinsystem/model" +) type SkinsRepository interface { FindByUsername(username string) (*model.Skin, error) FindByUserId(id int) (*model.Skin, error) Save(skin *model.Skin) error } + +type CapesRepository interface { + FindByUsername(username string) (model.Cape, error) +} diff --git a/repositories/capes.go b/repositories/capes.go deleted file mode 100644 index 40b7348..0000000 --- a/repositories/capes.go +++ /dev/null @@ -1,7 +0,0 @@ -package repositories - -import "elyby/minecraft-skinsystem/model" - -type CapesRepository interface { - FindByUsername(username string) (model.Cape, error) -} diff --git a/ui/service.go b/ui/service.go index b589b63..d622b2c 100644 --- a/ui/service.go +++ b/ui/service.go @@ -2,19 +2,19 @@ package ui import ( "github.com/mono83/slf/wd" - "elyby/minecraft-skinsystem/repositories" + "elyby/minecraft-skinsystem/interfaces" ) type uiService struct { - logger wd.Watchdog - skinsRepo repositories.SkinsRepository - capesRepo repositories.CapesRepository + logger wd.Watchdog + skinsRepo interfaces.SkinsRepository + capesRepo interfaces.CapesRepository } func NewUiService( logger wd.Watchdog, - skinsRepo repositories.SkinsRepository, - capesRepo repositories.CapesRepository, + skinsRepo interfaces.SkinsRepository, + capesRepo interfaces.CapesRepository, ) (*uiService, error) { return &uiService{ logger: logger, diff --git a/worker/worker.go b/worker/worker.go index bbdfcbb..142f3af 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -7,12 +7,12 @@ import ( "github.com/streadway/amqp" "elyby/minecraft-skinsystem/model" - "elyby/minecraft-skinsystem/repositories" + "elyby/minecraft-skinsystem/interfaces" ) type Services struct { Channel *amqp.Channel - SkinsRepo repositories.SkinsRepository + SkinsRepo interfaces.SkinsRepository Logger wd.Watchdog }