Compare commits
No commits in common. "main" and "v1.0.0" have entirely different histories.
1 changed files with 10 additions and 16 deletions
14
storage.go
14
storage.go
|
@ -42,9 +42,6 @@ type Config struct {
|
|||
S3AccessKey string
|
||||
|
||||
S3BucketName string
|
||||
|
||||
// Override default s3 client.
|
||||
MinioClient *minio.Client
|
||||
}
|
||||
|
||||
// New creates a new storage interface
|
||||
|
@ -57,9 +54,6 @@ func New(config Config) (*Storage, error) {
|
|||
|
||||
switch config.Type {
|
||||
case "minio", "s3":
|
||||
if config.MinioClient != nil {
|
||||
newStorage.s3Client = config.MinioClient
|
||||
} else {
|
||||
s3Client, err := minio.New(config.S3Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(config.S3AccessID, config.S3AccessKey, ""),
|
||||
Secure: config.S3Secure,
|
||||
|
@ -67,19 +61,19 @@ func New(config Config) (*Storage, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newStorage.s3Client = s3Client
|
||||
}
|
||||
|
||||
bucketExists, err := newStorage.s3Client.BucketExists(newStorage.ctx, config.S3BucketName)
|
||||
bucketExists, err := s3Client.BucketExists(newStorage.ctx, config.S3BucketName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !bucketExists {
|
||||
if err := newStorage.s3Client.MakeBucket(newStorage.ctx, config.S3BucketName, minio.MakeBucketOptions{}); err != nil {
|
||||
if err := s3Client.MakeBucket(newStorage.ctx, config.S3BucketName, minio.MakeBucketOptions{}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
newStorage.s3Client = s3Client
|
||||
case "local":
|
||||
if statInfo, err := os.Stat(config.Path); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||
if err := os.MkdirAll(config.Path, 0740); err != nil {
|
||||
|
|
Loading…
Reference in a new issue