forked from FabianVowie/Lithium
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
581 B
27 lines
581 B
package storage
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/spf13/afero"
|
|
)
|
|
|
|
type IStorageProvider interface {
|
|
store(bucketName string, objectName string, data []byte)
|
|
}
|
|
|
|
type FileSystemStorageProvider struct {
|
|
fileSystem afero.Fs
|
|
basePath string
|
|
}
|
|
|
|
func (sp FileSystemStorageProvider) store(bucketName string, objectName string, data []byte) {
|
|
directoryPath := filepath.Join(sp.basePath, bucketName)
|
|
|
|
sp.fileSystem.MkdirAll(directoryPath, os.ModePerm)
|
|
|
|
filePath := filepath.Join(directoryPath, objectName)
|
|
|
|
afero.WriteFile(sp.fileSystem, filePath, data, os.ModePerm)
|
|
}
|