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