generated from VLADIMIR/template
up
This commit is contained in:
@@ -38,13 +38,19 @@ func NewRustFSStorage(
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
defer cancel()
|
||||
err = client.CreateBucket(
|
||||
ctx,
|
||||
bucket,
|
||||
)
|
||||
exists, err := client.BucketExists(ctx, bucket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exists {
|
||||
err = client.CreateBucket(ctx, bucket)
|
||||
if err != nil {
|
||||
var apiErr smithy.APIError
|
||||
if !errors.As(err, &apiErr) || apiErr.ErrorCode() != "BucketAlreadyOwnedByYou" {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &storage{
|
||||
client: client,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package file_storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
)
|
||||
|
||||
// IStreamStorage supports large private objects without loading them into memory.
|
||||
type IStreamStorage interface {
|
||||
PutStream(context.Context, string, io.Reader, string) error
|
||||
Open(context.Context, string) (io.ReadCloser, error)
|
||||
Delete(context.Context, string) error
|
||||
}
|
||||
|
||||
// NewPrivateRustFSStorage uses an independent bucket with no public file route or policy.
|
||||
func NewPrivateRustFSStorage(ctx context.Context, endpoint, user, password, bucket string) (IStreamStorage, error) {
|
||||
files, err := NewRustFSStorage(ctx, endpoint, user, password, bucket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return files.(*storage), nil
|
||||
}
|
||||
|
||||
func (s *storage) PutStream(ctx context.Context, key string, body io.Reader, mime string) error {
|
||||
return s.client.PutObject(ctx, s.bucket, key, body, mime)
|
||||
}
|
||||
|
||||
func (s *storage) Open(ctx context.Context, key string) (io.ReadCloser, error) {
|
||||
return s.client.GetObject(ctx, s.bucket, key)
|
||||
}
|
||||
Reference in New Issue
Block a user