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