finally getting info on files

This commit is contained in:
2026-05-09 09:31:04 -06:00
parent 56fd10bccf
commit 96dd4949c2
+42 -10
View File
@@ -4,12 +4,14 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"path/filepath"
"time"
"github.com/joho/godotenv" "github.com/joho/godotenv"
) )
func resolveFileStorePath(file_store_path string) { func resolveFileStorePath(fileStorePath string) {
err := os.MkdirAll(file_store_path, os.ModePerm) err := os.MkdirAll(fileStorePath, os.ModePerm)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -26,17 +28,47 @@ type StoredFileNode struct {
Modified time.Time `json:"modified_at"` // last modification date Modified time.Time `json:"modified_at"` // last modification date
} }
func readFilesFromFileStorePath(file_store_path string) { func readFilesFromFileStorePath(fileStorePath string) {
files, err := os.ReadDir(file_store_path) files, err := os.ReadDir(fileStorePath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
shownNodes := []StoredFileNode{}
for _, file := range files { for _, file := range files {
if !file.IsDir() { fullPath := filepath.Join(fileStorePath, file.Name())
fmt.Println(file.Name()) fileStat, err := os.Stat(fullPath)
if err != nil {
log.Fatal(err)
} }
fmt.Println(fileStat.Size())
fileInfo, err := file.Info() // This returns an os.FileInfo
if err != nil {
continue
} }
// generate new StoredFileNode
newNode := StoredFileNode{
Name: file.Name(),
Path: fileStorePath,
Size: fileStat.Size(),
Extension: "--",
MimeType: "--",
Permissions: "--",
IsFolder: false,
Modified: fileInfo.ModTime(),
}
if file.IsDir() {
newNode.IsFolder = true
}
shownNodes = append(shownNodes, newNode)
}
fmt.Println(shownNodes)
} }
func main() { func main() {
@@ -47,12 +79,12 @@ func main() {
port := os.Getenv("PORT") port := os.Getenv("PORT")
file_store_path := os.Getenv("STORAGE_PATH") fileStorePath := os.Getenv("STORAGE_PATH")
resolveFileStorePath(file_store_path) resolveFileStorePath(fileStorePath)
fmt.Printf("in the future I will listen on port: %s\n", port) fmt.Printf("in the future I will listen on port: %s\n", port)
fmt.Printf("Reading files from: %s\n", file_store_path) fmt.Printf("Reading files from: %s\n", fileStorePath)
readFilesFromFileStorePath(file_store_path) readFilesFromFileStorePath(fileStorePath)
} }