From e299a488860770d4c39c669b9c4c5d0a2e081978 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 5 Aug 2024 10:34:30 +0000 Subject: [PATCH] 1 --- config/instance.go | 3 +++ config/proxy.go | 2 +- pkg/core/core.go | 6 ++++-- pkg/proc/interaction.go | 5 ++++- pkg/storage/storage.go | 11 +++++++---- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/config/instance.go b/config/instance.go index fbdc883..f7083ab 100644 --- a/config/instance.go +++ b/config/instance.go @@ -64,6 +64,9 @@ const ( ) func EmbedDefaults(cfgInstance *Instance) { + if cfgInstance.StorageCnf.StorageType == "" { + cfgInstance.StorageCnf.StorageType = "s3" + } if cfgInstance.StorageCnf.StorageConcurrency == 0 { cfgInstance.StorageCnf.StorageConcurrency = DefaultStorageConcurrency } diff --git a/config/proxy.go b/config/proxy.go index e99d811..c78853a 100644 --- a/config/proxy.go +++ b/config/proxy.go @@ -1,5 +1,5 @@ package config type Proxy struct { - ConsolePort string `json:"console_port" toml:"console+port" yaml:"console_port"` + ConsolePort string `json:"console_port" toml:"console_port" yaml:"console_port"` } diff --git a/pkg/core/core.go b/pkg/core/core.go index cea946f..f629612 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -116,10 +116,12 @@ func (i *Instance) Run(instanceCnf *config.Instance) error { return err } - s := storage.NewStorage( + s, err := storage.NewStorage( &instanceCnf.StorageCnf, ) - + if err != nil { + return err + } var cr crypt.Crypter = nil if instanceCnf.CryptoCnf.GPGKeyPath != "" { cr, err = crypt.NewCrypto(&instanceCnf.CryptoCnf) diff --git a/pkg/proc/interaction.go b/pkg/proc/interaction.go index 60e9d6d..fbc4380 100644 --- a/pkg/proc/interaction.go +++ b/pkg/proc/interaction.go @@ -211,7 +211,10 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl return nil } config.EmbedDefaults(&instanceCnf) - oldStorage := storage.NewStorage(&instanceCnf.StorageCnf) + oldStorage, err := storage.NewStorage(&instanceCnf.StorageCnf) + if err != nil { + return err + } fmt.Printf("ok new conf: %v\n", instanceCnf) //list objects diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index b4c78ff..f12ea6f 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -1,6 +1,7 @@ package storage import ( + "fmt" "io" "github.com/yezzey-gp/yproxy/config" @@ -30,16 +31,18 @@ type StorageInteractor interface { StorageMover } -func NewStorage(cnf *config.Storage) StorageInteractor { +func NewStorage(cnf *config.Storage) (StorageInteractor, error) { switch cnf.StorageType { case "fs": return &FileStorageInteractor{ cnf: cnf, - } - default: + }, nil + case "s3": return &S3StorageInteractor{ pool: NewSessionPool(cnf), cnf: cnf, - } + }, nil + default: + return nil, fmt.Errorf("wrong storage type " + cnf.StorageType) } }