diff --git a/cmd/serve.go b/cmd/serve.go index cff9bb6..1165de3 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -34,12 +34,12 @@ var serveCmd = &cobra.Command{ // Skins repository logger.Info("Connecting to redis") - skinsRepoCfg := &redis.Config{ + skinsRepoCfg := &redis.RedisSkinsFactory{ //Addr: "redis:6379", Addr: "localhost:16379", PollSize: 10, } - skinsRepo, err := skinsRepoCfg.CreateRepo() + skinsRepo, err := skinsRepoCfg.Create() if err != nil { logger.Emergency(fmt.Sprintf("Error on creating skins repo: %v", err)) return @@ -48,10 +48,10 @@ var serveCmd = &cobra.Command{ // Capes repository _, file, _, _ := runtime.Caller(0) - capesRepoCfg := &files.Config{ + capesRepoCfg := &files.FilesystemCapesFactory{ StoragePath: path.Join(filepath.Dir(file), "data/capes"), } - capesRepo, err := capesRepoCfg.CreateRepo() + capesRepo, err := capesRepoCfg.Create() if err != nil { logger.Emergency(fmt.Sprintf("Error on creating capes repo: %v", err)) return diff --git a/db/capes/config.go b/db/capes/config.go index 141d7f0..6b2c7a2 100644 --- a/db/capes/config.go +++ b/db/capes/config.go @@ -2,6 +2,6 @@ package capes import "elyby/minecraft-skinsystem/model" -type CapesRepositoryConfig interface { - CreateRepo() (model.CapesRepository, error) +type CapesRepositoryCreator interface { + Create() (model.CapesRepository, error) } diff --git a/db/capes/files/db.go b/db/capes/files/db.go index eb4e058..41fc2b2 100644 --- a/db/capes/files/db.go +++ b/db/capes/files/db.go @@ -2,10 +2,10 @@ package files import "elyby/minecraft-skinsystem/model" -type Config struct { +type FilesystemCapesFactory struct { StoragePath string } -func (cfg *Config) CreateRepo() (model.CapesRepository, error) { +func (cfg *FilesystemCapesFactory) Create() (model.CapesRepository, error) { return &filesDb{path: cfg.StoragePath}, nil } diff --git a/db/capes/files/errors.go b/db/capes/files/errors.go index 79aa91f..8c3aa5e 100644 --- a/db/capes/files/errors.go +++ b/db/capes/files/errors.go @@ -1,11 +1,9 @@ package files -import "fmt" - -type CapeNotFound struct { +type CapeNotFoundError struct { Who string } -func (e CapeNotFound) Error() string { - return fmt.Sprintf("Cape file not found. Required username \"%v\"", e.Who) +func (e CapeNotFoundError) Error() string { + return "Cape file not found." } diff --git a/db/capes/files/repository.go b/db/capes/files/repository.go index 848037d..0c70e31 100644 --- a/db/capes/files/repository.go +++ b/db/capes/files/repository.go @@ -17,7 +17,7 @@ func (repository *filesDb) FindByUsername(username string) (model.Cape, error) { capePath := path.Join(repository.path, strings.ToLower(username) + ".png") file, err := os.Open(capePath) if err != nil { - return record, CapeNotFound{username} + return record, CapeNotFoundError{username} } record.File = file diff --git a/db/skins/config.go b/db/skins/config.go index 757e5c3..7911bbd 100644 --- a/db/skins/config.go +++ b/db/skins/config.go @@ -2,6 +2,6 @@ package skins import "elyby/minecraft-skinsystem/model" -type SkinsRepositoryConfig interface { - CreateRepo() (model.SkinsRepository, error) +type SkinsRepositoryCreator interface { + Create() (model.SkinsRepository, error) } diff --git a/db/skins/redis/commands.go b/db/skins/redis/commands.go index 629664a..75f9ad7 100644 --- a/db/skins/redis/commands.go +++ b/db/skins/redis/commands.go @@ -21,7 +21,7 @@ func (db *redisDb) FindByUsername(username string) (model.Skin, error) { redisKey := buildKey(username) response := db.conn.Cmd("GET", redisKey) if response.IsType(redis.Nil) { - return record, SkinNotFound{username} + return record, SkinNotFoundError{username} } encodedResult, err := response.Bytes() @@ -49,7 +49,7 @@ func (db *redisDb) FindByUsername(username string) (model.Skin, error) { func (db *redisDb) FindByUserId(id int) (model.Skin, error) { response := db.conn.Cmd("HGET", accountIdToUsernameKey, id) if response.IsType(redis.Nil) { - return model.Skin{}, SkinNotFound{"unknown"} + return model.Skin{}, SkinNotFoundError{"unknown"} } username, _ := response.Str() diff --git a/db/skins/redis/db.go b/db/skins/redis/db.go index 765da18..b224a7f 100644 --- a/db/skins/redis/db.go +++ b/db/skins/redis/db.go @@ -6,12 +6,12 @@ import ( "github.com/mediocregopher/radix.v2/pool" ) -type Config struct { +type RedisSkinsFactory struct { Addr string PollSize int } -func (cfg *Config) CreateRepo() (model.SkinsRepository, error) { +func (cfg *RedisSkinsFactory) Create() (model.SkinsRepository, error) { conn, err := pool.New("tcp", cfg.Addr, cfg.PollSize) if err != nil { return nil, err @@ -19,5 +19,5 @@ func (cfg *Config) CreateRepo() (model.SkinsRepository, error) { // TODO: здесь можно запустить горутину по восстановлению соединения - return &redisDb{conn: conn}, err + return &redisDb{conn: conn}, nil } diff --git a/db/skins/redis/errors.go b/db/skins/redis/errors.go index f9fc0cb..a4388bb 100644 --- a/db/skins/redis/errors.go +++ b/db/skins/redis/errors.go @@ -1,12 +1,9 @@ package redis -import "fmt" - -type SkinNotFound struct { +type SkinNotFoundError struct { Who string } -func (e SkinNotFound) Error() string { - return fmt.Sprintf("Skin data not found. Required username \"%v\"", e.Who) +func (e SkinNotFoundError) Error() string { + return "Skin data not found." } -