package storage import ( "os" "path/filepath" "github.com/spf13/afero" ) type IStorageProvider interface { StoreRaw(bucketName string, objectName string, data []byte) string StoreExisting(bucketName string, objectName string, existingFilePath string) string } type FileSystemStorageProvider struct { fileSystem afero.Fs basePath string } func (sp FileSystemStorageProvider) StoreRaw(bucketName string, objectName string, data []byte) string { 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) return filePath } func (sp FileSystemStorageProvider) StoreExisting(bucketName string, objectName string, existingFilePath string) string { bytesRead, _ := afero.ReadFile(sp.fileSystem, existingFilePath) return sp.StoreRaw(bucketName, objectName, bytesRead) } }