diff options
author | Mike Crute <mike@crute.us> | 2023-08-14 21:24:54 -0700 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2023-08-14 21:24:54 -0700 |
commit | 0b12194c52d0af5eb5339cb96905d86d175d6a12 (patch) | |
tree | 573ddd5c61899ae12d829465d4cf262843a24a03 /app | |
parent | 746e5d91e7c23fe702040cfb5b10b60d7537dbfa (diff) | |
download | websocket_proxy-0b12194c52d0af5eb5339cb96905d86d175d6a12.tar.bz2 websocket_proxy-0b12194c52d0af5eb5339cb96905d86d175d6a12.tar.xz websocket_proxy-0b12194c52d0af5eb5339cb96905d86d175d6a12.zip |
Support indexing clients
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/client_list.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/controllers/client_list.go b/app/controllers/client_list.go new file mode 100644 index 0000000..f6531da --- /dev/null +++ b/app/controllers/client_list.go | |||
@@ -0,0 +1,39 @@ | |||
1 | package controllers | ||
2 | |||
3 | import ( | ||
4 | "io/fs" | ||
5 | "net/http" | ||
6 | "time" | ||
7 | |||
8 | "github.com/labstack/echo/v4" | ||
9 | ) | ||
10 | |||
11 | type clientEntry struct { | ||
12 | Filename string | ||
13 | LastModified time.Time | ||
14 | ByteSize int64 | ||
15 | } | ||
16 | |||
17 | func ListClients(clients fs.FS) echo.HandlerFunc { | ||
18 | return func(c echo.Context) error { | ||
19 | out := struct{ Models []clientEntry }{[]clientEntry{}} | ||
20 | |||
21 | fs.WalkDir(clients, "clients", func(path string, d fs.DirEntry, err error) error { | ||
22 | if path == "clients/keep" || d.IsDir() { | ||
23 | return nil | ||
24 | } | ||
25 | fi, err := d.Info() | ||
26 | if err != nil { | ||
27 | return err | ||
28 | } | ||
29 | out.Models = append(out.Models, clientEntry{ | ||
30 | Filename: d.Name(), | ||
31 | LastModified: fi.ModTime(), | ||
32 | ByteSize: fi.Size(), | ||
33 | }) | ||
34 | return nil | ||
35 | }) | ||
36 | |||
37 | return c.Render(http.StatusOK, "client_index.tpl", out) | ||
38 | } | ||
39 | } | ||