|
|
@ -8,8 +8,8 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
type IStorageProvider interface { |
|
|
|
StoreRaw(bucketName string, objectName string, data []byte) string |
|
|
|
StoreExisting(bucketName string, objectName string, existingFilePath string) string |
|
|
|
StoreRaw(bucketName string, objectName string, data []byte) (string, error) |
|
|
|
StoreExisting(bucketName string, objectName string, existingFilePath string) (string, error) |
|
|
|
} |
|
|
|
|
|
|
|
type FileSystemStorageProvider struct { |
|
|
@ -17,19 +17,23 @@ type FileSystemStorageProvider struct { |
|
|
|
basePath string |
|
|
|
} |
|
|
|
|
|
|
|
func (sp FileSystemStorageProvider) StoreRaw(bucketName string, objectName string, data []byte) string { |
|
|
|
func (sp FileSystemStorageProvider) StoreRaw(bucketName string, objectName string, data []byte) (string, error) { |
|
|
|
directoryPath := filepath.Join(sp.basePath, bucketName) |
|
|
|
|
|
|
|
sp.fileSystem.MkdirAll(directoryPath, os.ModePerm) |
|
|
|
if err := sp.fileSystem.MkdirAll(directoryPath, os.ModePerm); err != nil { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
|
|
|
|
filePath := filepath.Join(directoryPath, objectName) |
|
|
|
|
|
|
|
afero.WriteFile(sp.fileSystem, filePath, data, os.ModePerm) |
|
|
|
if err := afero.WriteFile(sp.fileSystem, filePath, data, os.ModePerm); err != nil { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
|
|
|
|
return filePath |
|
|
|
return filePath, nil |
|
|
|
} |
|
|
|
|
|
|
|
func (sp FileSystemStorageProvider) StoreExisting(bucketName string, objectName string, existingFilePath string) string { |
|
|
|
func (sp FileSystemStorageProvider) StoreExisting(bucketName string, objectName string, existingFilePath string) (string, error) { |
|
|
|
bytesRead, _ := afero.ReadFile(sp.fileSystem, existingFilePath) |
|
|
|
|
|
|
|
return sp.StoreRaw(bucketName, objectName, bytesRead) |
|
|
|