aboutsummaryrefslogtreecommitdiff
path: root/pkg/database/localfs
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-02-26 19:54:48 +0100
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-18 16:30:36 +0200
commitc8e1328164e9ffbd681c3c0e449f1e6b9856b896 (patch)
treefaee639a4c55c5dc3bfc59a5400026822c40221d /pkg/database/localfs
downloadlens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.tar.gz
lens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.tar.bz2
lens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.zip
feat: Inicial commit
It contains rough template for the server and runners. It contains rough template for the server and runners.
Diffstat (limited to 'pkg/database/localfs')
-rw-r--r--pkg/database/localfs/filesystem.go49
1 files changed, 49 insertions, 0 deletions
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)
+}