mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
@@ -3,6 +3,7 @@ package actions
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gomods/athens/pkg/config"
|
||||
"github.com/gomods/athens/pkg/errors"
|
||||
@@ -17,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
// GetStorage returns storage backend based on env configuration
|
||||
func GetStorage(storageType string, storageConfig *config.StorageConfig) (storage.Backend, error) {
|
||||
func GetStorage(storageType string, storageConfig *config.StorageConfig, timeout time.Duration) (storage.Backend, error) {
|
||||
const op errors.Op = "actions.GetStorage"
|
||||
switch storageType {
|
||||
case "memory":
|
||||
@@ -26,7 +27,7 @@ func GetStorage(storageType string, storageConfig *config.StorageConfig) (storag
|
||||
if storageConfig.Mongo == nil {
|
||||
return nil, errors.E(op, "Invalid Mongo Storage Configuration")
|
||||
}
|
||||
return mongo.NewStorage(storageConfig.Mongo)
|
||||
return mongo.NewStorage(storageConfig.Mongo, timeout)
|
||||
case "disk":
|
||||
if storageConfig.Disk == nil {
|
||||
return nil, errors.E(op, "Invalid Disk Storage Configuration")
|
||||
@@ -42,17 +43,17 @@ func GetStorage(storageType string, storageConfig *config.StorageConfig) (storag
|
||||
if storageConfig.Minio == nil {
|
||||
return nil, errors.E(op, "Invalid Minio Storage Configuration")
|
||||
}
|
||||
return minio.NewStorage(storageConfig.Minio)
|
||||
return minio.NewStorage(storageConfig.Minio, timeout)
|
||||
case "gcp":
|
||||
if storageConfig.GCP == nil {
|
||||
return nil, errors.E(op, "Invalid GCP Storage Configuration")
|
||||
}
|
||||
return gcp.New(context.Background(), storageConfig.GCP)
|
||||
return gcp.New(context.Background(), storageConfig.GCP, timeout)
|
||||
case "s3":
|
||||
if storageConfig.S3 == nil {
|
||||
return nil, errors.E(op, "Invalid S3 Storage Configuration")
|
||||
}
|
||||
return s3.New(storageConfig.S3)
|
||||
return s3.New(storageConfig.S3, timeout)
|
||||
default:
|
||||
return nil, fmt.Errorf("storage type %s is unknown", storageType)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user