Skip to content

Commit 853c4c7

Browse files
Make http list call recurse
1 parent 0b88314 commit 853c4c7

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

pkg/server/server.go

+18-10
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,29 @@ func (s *Server) list(rw http.ResponseWriter, req *http.Request) {
116116
return
117117
}
118118

119-
files, err := os.ReadDir(path)
119+
var result []string
120+
err := fs.WalkDir(os.DirFS(path), ".", func(path string, d fs.DirEntry, err error) error {
121+
if err != nil {
122+
return err
123+
}
124+
if strings.HasPrefix(d.Name(), ".") {
125+
if d.IsDir() && d.Name() != "." {
126+
return fs.SkipDir
127+
}
128+
return nil
129+
}
130+
131+
if !d.IsDir() && strings.HasSuffix(d.Name(), ".gpt") {
132+
result = append(result, path)
133+
}
134+
135+
return nil
136+
})
120137
if err != nil {
121138
http.Error(rw, err.Error(), http.StatusInternalServerError)
122139
return
123140
}
124141

125-
var result []string
126-
for _, file := range files {
127-
if file.IsDir() && !strings.HasPrefix(file.Name(), ".") {
128-
result = append(result, filepath.Join(path, file.Name())+"/")
129-
} else if strings.HasSuffix(file.Name(), ".gpt") {
130-
result = append(result, filepath.Join(path, file.Name()))
131-
}
132-
}
133-
134142
_ = enc.Encode(result)
135143
}
136144

0 commit comments

Comments
 (0)