Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/server/internal/utils/files.go

31 lines
483 B
Go
Raw Normal View History

2022-11-03 15:20:32 +13:00
package utils
import (
"os"
"m1k1o/neko/internal/types"
)
func ListFiles(path string) (*[]types.FileListItem, error) {
items, err := os.ReadDir(path)
if err != nil {
return nil, err
}
out := make([]types.FileListItem, len(items))
for i, item := range items {
var itemType string = ""
if item.IsDir() {
itemType = "dir"
} else {
itemType = "file"
}
out[i] = types.FileListItem{
Filename: item.Name(),
Type: itemType,
}
}
return &out, nil
}