52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package storageRepo
|
|
|
|
import (
|
|
"os"
|
|
|
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
|
)
|
|
|
|
type UIStorageRepo interface {
|
|
EntryInfo(absPath string) (os.FileInfo, error)
|
|
ListContent(absPath string) (*[]model.EntryInList, error)
|
|
OpenFile(absPath string) (*os.File, error)
|
|
CreateFolder(absPath string, name string) error
|
|
}
|
|
|
|
type StorageRepo struct{}
|
|
|
|
func New() UIStorageRepo {
|
|
return &StorageRepo{}
|
|
}
|
|
|
|
func (r *StorageRepo) EntryInfo(absPath string) (os.FileInfo, error) {
|
|
return os.Stat(absPath)
|
|
}
|
|
|
|
func (r *StorageRepo) ListContent(absPath string) (*[]model.EntryInList, error) {
|
|
entries, err := os.ReadDir(absPath)
|
|
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(absPath string) (*os.File, error) {
|
|
return os.Open(absPath)
|
|
}
|
|
|
|
func (r *StorageRepo) CreateFolder(absPath string, name string) error {
|
|
os.(absPath)
|
|
}
|