mirror of
https://github.com/m1k1o/neko.git
synced 2025-07-23 19:49:02 +02:00
listing of files on connect
This commit is contained in:
parent
1505abb703
commit
70e84c5840
12 changed files with 160 additions and 26 deletions
30
server/internal/utils/files.go
Normal file
30
server/internal/utils/files.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue