From c8e1328164e9ffbd681c3c0e449f1e6b9856b896 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Sun, 26 Feb 2023 19:54:48 +0100 Subject: feat: Inicial commit It contains rough template for the server and runners. It contains rough template for the server and runners. --- pkg/database/localfs/filesystem.go | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 pkg/database/localfs/filesystem.go (limited to 'pkg/database/localfs') diff --git a/pkg/database/localfs/filesystem.go b/pkg/database/localfs/filesystem.go new file mode 100644 index 0000000..c7c6458 --- /dev/null +++ b/pkg/database/localfs/filesystem.go @@ -0,0 +1,49 @@ +package localfs + +import ( + "io/fs" + "os" + "path" + "strings" +) + +type FileSystemRepository struct { + root string +} + +func NewFileSystemRepository(root string) *FileSystemRepository { + return &FileSystemRepository{ + root: root, + } +} + +func (self *FileSystemRepository) getFilesFromPath(filepath string) ([]fs.FileInfo, error) { + dirs, err := os.ReadDir(filepath) + if err != nil { + return nil, err + } + + infos := make([]fs.FileInfo, 0, len(dirs)) + for _, dir := range dirs { + if strings.HasPrefix(dir.Name(), ".") { + continue + } + info, err := dir.Info() + if err != nil { + return nil, err + } + infos = append(infos, info) + } + + return infos, nil +} + +func (self *FileSystemRepository) List(filepath string) ([]fs.FileInfo, error) { + workingPath := path.Join(self.root, filepath) + return self.getFilesFromPath(workingPath) +} + +func (self *FileSystemRepository) Stat(filepath string) (fs.FileInfo, error) { + workingPath := path.Join(self.root, filepath) + return os.Stat(workingPath) +} -- cgit v1.2.3