|
|
@ -7,14 +7,18 @@ import ( |
|
|
|
"github.com/spf13/afero" |
|
|
|
) |
|
|
|
|
|
|
|
const StorageFolderName = "files" |
|
|
|
|
|
|
|
type IStorageProvider interface { |
|
|
|
StoreRaw(bucketName string, objectName string, data []byte) (string, error) |
|
|
|
StoreExisting(bucketName string, objectName string, existingFilePath string) (string, error) |
|
|
|
GetPath(bucketName string, objectName string) string |
|
|
|
} |
|
|
|
|
|
|
|
type FileSystemStorageProvider struct { |
|
|
|
fileSystem afero.Fs |
|
|
|
basePath string |
|
|
|
wd string |
|
|
|
} |
|
|
|
|
|
|
|
func (sp FileSystemStorageProvider) StoreRaw(bucketName string, objectName string, data []byte) (string, error) { |
|
|
@ -42,14 +46,19 @@ func (sp FileSystemStorageProvider) StoreExisting(bucketName string, objectName |
|
|
|
return sp.StoreRaw(bucketName, objectName, bytesRead) |
|
|
|
} |
|
|
|
|
|
|
|
func (sp FileSystemStorageProvider) GetPath(bucketName string, objectName string) string { |
|
|
|
return filepath.Join(sp.wd, StorageFolderName, sp.basePath, bucketName, objectName) |
|
|
|
} |
|
|
|
|
|
|
|
func GetFileSystemStorageProvider(basePath string, wd string) FileSystemStorageProvider { |
|
|
|
if wd == "" { |
|
|
|
wd, _ = os.Getwd() |
|
|
|
} |
|
|
|
|
|
|
|
return FileSystemStorageProvider{ |
|
|
|
fileSystem: afero.NewBasePathFs(afero.NewOsFs(), filepath.Join(wd, "files")), |
|
|
|
fileSystem: afero.NewBasePathFs(afero.NewOsFs(), filepath.Join(wd, StorageFolderName)), |
|
|
|
basePath: basePath, |
|
|
|
wd: wd, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|