Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
visill committed Aug 5, 2024
1 parent e4c2682 commit e299a48
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions config/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion config/proxy.go
Original file line number Diff line number Diff line change
@@ -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"`
}
6 changes: 4 additions & 2 deletions pkg/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pkg/proc/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage

import (
"fmt"
"io"

"github.com/yezzey-gp/yproxy/config"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit e299a48

Please sign in to comment.