navigation

This commit is contained in:
2026-08-07 19:20:16 +02:00
parent 5810c4c94f
commit ff6ef46cd4
78 changed files with 681 additions and 282 deletions
+109
View File
@@ -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)
}