infoalloggi-monorepo/apps/backend/storage_handlers/storage_handler.go

54 lines
884 B
Go
Raw Normal View History

2025-08-04 17:45:44 +02:00
package storagehandlers
import (
"errors"
"mime/multipart"
)
var (
Storagepath string
)
type StorageHandler interface {
Init() error
Add(file *multipart.FileHeader, fileId string) error
Delete(filename string) error
Get(filename string) (string, error)
List() ([]string, error)
}
type StorageStrategy string
const (
FS StorageStrategy = "fs"
S3 StorageStrategy = "s3"
)
func NewStorageHandler(strategy StorageStrategy) (StorageHandler, error) {
if Storagepath == "" {
return nil, errors.New("storage path not set")
}
switch strategy {
case FS:
h := NewFsHandler()
err := h.Init()
if err != nil {
return nil, err
}
return h, nil
case S3:
h, err := NewS3Handler()
if err != nil {
return nil, err
}
err = h.Init()
if err != nil {
return nil, err
}
return h, nil
default:
return nil, errors.New("invalid storage strategy")
}
}