Micro-service for file storage and processing written in Go
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

  1. package storage
  2. import (
  3. "os"
  4. "path/filepath"
  5. "github.com/spf13/afero"
  6. )
  7. type IStorageProvider interface {
  8. store(bucketName string, objectName string, data []byte)
  9. }
  10. type FileSystemStorageProvider struct {
  11. fileSystem afero.Fs
  12. basePath string
  13. }
  14. func (sp FileSystemStorageProvider) store(bucketName string, objectName string, data []byte) {
  15. directoryPath := filepath.Join(sp.basePath, bucketName)
  16. sp.fileSystem.MkdirAll(directoryPath, os.ModePerm)
  17. filePath := filepath.Join(directoryPath, objectName)
  18. afero.WriteFile(sp.fileSystem, filePath, data, os.ModePerm)
  19. }