- Updated `fs.go` and `minio.go` to replace hardcoded storage paths with values from the new config package. - Introduced a new `config` package to manage application configuration, including database and storage settings. - Removed the `models.go` file from `typedefs` as it was no longer needed. - Added a new `config.go` file to handle loading environment variables and application settings. - Created a new `types.go` file in `typedefs` to define storage strategies. - Updated `storage_handler.go` to utilize the new configuration structure.
45 lines
843 B
Go
45 lines
843 B
Go
package storagehandlers
|
|
|
|
import (
|
|
"backend/config"
|
|
"backend/typesdefs"
|
|
|
|
"errors"
|
|
"mime/multipart"
|
|
)
|
|
|
|
type StorageHandler interface {
|
|
Init() error
|
|
Add(file *multipart.FileHeader, fileId string) error
|
|
Delete(filename string) error
|
|
Get(filename string) (string, error)
|
|
List() ([]string, error)
|
|
}
|
|
|
|
func NewStorageHandler(strategy typesdefs.StorageStrategy) (StorageHandler, error) {
|
|
if config.Cfg.Storage.Path == "" {
|
|
return nil, errors.New("storage path not set")
|
|
}
|
|
switch strategy {
|
|
case typesdefs.FS:
|
|
h := NewFsHandler()
|
|
err := h.Init()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return h, nil
|
|
|
|
case typesdefs.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")
|
|
}
|
|
}
|