|
@ -8,8 +8,8 @@ import ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type IStorageProvider interface { |
|
|
type IStorageProvider interface { |
|
|
storeRaw(bucketName string, objectName string, data []byte) |
|
|
|
|
|
storeExisting(bucketName string, objectName string, existingFilePath string) |
|
|
|
|
|
|
|
|
storeRaw(bucketName string, objectName string, data []byte) string |
|
|
|
|
|
storeExisting(bucketName string, objectName string, existingFilePath string) string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type FileSystemStorageProvider struct { |
|
|
type FileSystemStorageProvider struct { |
|
@ -17,7 +17,7 @@ type FileSystemStorageProvider struct { |
|
|
basePath string |
|
|
basePath string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (sp FileSystemStorageProvider) storeRaw(bucketName string, objectName string, data []byte) { |
|
|
|
|
|
|
|
|
func (sp FileSystemStorageProvider) storeRaw(bucketName string, objectName string, data []byte) string { |
|
|
directoryPath := filepath.Join(sp.basePath, bucketName) |
|
|
directoryPath := filepath.Join(sp.basePath, bucketName) |
|
|
|
|
|
|
|
|
sp.fileSystem.MkdirAll(directoryPath, os.ModePerm) |
|
|
sp.fileSystem.MkdirAll(directoryPath, os.ModePerm) |
|
@ -25,9 +25,12 @@ func (sp FileSystemStorageProvider) storeRaw(bucketName string, objectName strin |
|
|
filePath := filepath.Join(directoryPath, objectName) |
|
|
filePath := filepath.Join(directoryPath, objectName) |
|
|
|
|
|
|
|
|
afero.WriteFile(sp.fileSystem, filePath, data, os.ModePerm) |
|
|
afero.WriteFile(sp.fileSystem, filePath, data, os.ModePerm) |
|
|
|
|
|
|
|
|
|
|
|
return filePath |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (sp FileSystemStorageProvider) storeExisting(bucketName string, objectName string, existingFilePath string) { |
|
|
|
|
|
|
|
|
func (sp FileSystemStorageProvider) storeExisting(bucketName string, objectName string, existingFilePath string) string { |
|
|
bytesRead, _ := afero.ReadFile(sp.fileSystem, existingFilePath) |
|
|
bytesRead, _ := afero.ReadFile(sp.fileSystem, existingFilePath) |
|
|
sp.storeRaw(bucketName, objectName, bytesRead) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sp.storeRaw(bucketName, objectName, bytesRead) |
|
|
} |
|
|
} |