navigation
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"log"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
const bucketName = "lassistanoque"
|
||||
|
||||
type StorageProvider interface {
|
||||
EnsureBucket(
|
||||
ctx context.Context,
|
||||
bucketName string,
|
||||
) error
|
||||
PutObject(
|
||||
ctx context.Context,
|
||||
reader io.Reader,
|
||||
bucketName string,
|
||||
objectName string,
|
||||
filePath string,
|
||||
contentType string,
|
||||
) error
|
||||
GetObject(
|
||||
ctx context.Context,
|
||||
bucketName string,
|
||||
objectName string,
|
||||
filePath string,
|
||||
) (io.ReadCloser, error)
|
||||
DeleteObject(
|
||||
ctx context.Context,
|
||||
bucketName string,
|
||||
objectName string,
|
||||
filePath string,
|
||||
) error
|
||||
ExistsObject(
|
||||
ctx context.Context,
|
||||
bucketName string,
|
||||
objectName string,
|
||||
filePath string,
|
||||
) (bool, error)
|
||||
GetPresignedURL(
|
||||
ctx context.Context,
|
||||
bucketName string,
|
||||
objectName string,
|
||||
filePath string,
|
||||
Expiry time.Time,
|
||||
) (*url.URL, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
provider StorageProvider
|
||||
}
|
||||
|
||||
func NewService(provider StorageProvider) *Service {
|
||||
err := provider.EnsureBucket(
|
||||
context.Background(),
|
||||
bucketName,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal("error creating bucket", err)
|
||||
}
|
||||
return &Service{provider}
|
||||
}
|
||||
|
||||
func (s *Service) PutObject(
|
||||
ctx context.Context,
|
||||
reader io.Reader,
|
||||
objectName string,
|
||||
filePath string,
|
||||
contentType string,
|
||||
) error {
|
||||
return s.provider.PutObject(ctx, reader, bucketName, objectName, filePath, contentType)
|
||||
}
|
||||
|
||||
func (s *Service) GetObject(
|
||||
ctx context.Context,
|
||||
objectName string,
|
||||
filePath string,
|
||||
) (io.ReadCloser, error) {
|
||||
return s.provider.GetObject(ctx, bucketName, objectName, filePath)
|
||||
}
|
||||
|
||||
func (s *Service) DeleteObject(
|
||||
ctx context.Context,
|
||||
objectName string,
|
||||
filePath string,
|
||||
) error {
|
||||
return s.provider.DeleteObject(ctx, bucketName, objectName, filePath)
|
||||
}
|
||||
|
||||
func (s *Service) ExistsObject(
|
||||
ctx context.Context,
|
||||
objectName string,
|
||||
filePath string,
|
||||
) (bool, error) {
|
||||
return s.provider.ExistsObject(ctx, bucketName, objectName, filePath)
|
||||
}
|
||||
|
||||
func (s *Service) GetPresignedURL(
|
||||
ctx context.Context,
|
||||
objectName string,
|
||||
filePath string,
|
||||
Expiry time.Time,
|
||||
) (*url.URL, error) {
|
||||
return s.provider.GetPresignedURL(ctx, bucketName, objectName, filePath, Expiry)
|
||||
}
|
||||
Reference in New Issue
Block a user