68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
package storageRepo
|
|
|
|
import (
|
|
"mime/multipart"
|
|
"os"
|
|
|
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
|
)
|
|
|
|
type UIStorageRepo interface {
|
|
EntryInfo(abs_path string) (os.FileInfo, error)
|
|
ListContent(abs_path string) (*[]model.EntryInList, error)
|
|
OpenFile(abs_path string) (*os.File, error)
|
|
UploadFile(abs_path string, f *multipart.FileHeader) error
|
|
CreateFolder(abs_path string) error
|
|
DeleteFile(abs_path string) error
|
|
DeleteFolder(abs_path string) error
|
|
}
|
|
|
|
type StorageRepo struct{}
|
|
|
|
func New() UIStorageRepo {
|
|
return &StorageRepo{}
|
|
}
|
|
|
|
func (r *StorageRepo) EntryInfo(abs_path string) (os.FileInfo, error) {
|
|
return os.Stat(abs_path)
|
|
}
|
|
|
|
func (r *StorageRepo) ListContent(abs_path string) (*[]model.EntryInList, error) {
|
|
entries, err := os.ReadDir(abs_path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var entries_in_list []model.EntryInList
|
|
|
|
for _, entry := range entries {
|
|
var next_entry_in_list model.EntryInList
|
|
next_entry_in_list.Name = entry.Name()
|
|
next_entry_in_list.IsFolder = entry.IsDir()
|
|
|
|
entries_in_list = append(entries_in_list, next_entry_in_list)
|
|
}
|
|
|
|
return &entries_in_list, nil
|
|
}
|
|
|
|
func (r *StorageRepo) OpenFile(abs_path string) (*os.File, error) {
|
|
return os.Open(abs_path)
|
|
}
|
|
|
|
func (r *StorageRepo) UploadFile(abs_path string, f *multipart.FileHeader) error {
|
|
return nil
|
|
}
|
|
|
|
func (r *StorageRepo) CreateFolder(abs_path string) error {
|
|
return os.Mkdir(abs_path, 0755)
|
|
}
|
|
|
|
func (r *StorageRepo) DeleteFile(abs_path string) error {
|
|
return os.Remove(abs_path)
|
|
}
|
|
|
|
func (r *StorageRepo) DeleteFolder(abs_path string) error {
|
|
return os.RemoveAll(abs_path)
|
|
}
|