diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-03 10:42:07 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-03 10:42:07 +0200 |
| commit | 620b03459751a17632f6165b289206dc6d86ed7c (patch) | |
| tree | 186ab77201da3ad82e5a118561eb199a76955bc6 /backend/logs.go | |
| parent | 2d131a363645e4a32e47036742087acc4bf1379f (diff) | |
feat(backend): handle display all log
Diffstat (limited to 'backend/logs.go')
| -rw-r--r-- | backend/logs.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/backend/logs.go b/backend/logs.go index 50caec1..8b6a608 100644 --- a/backend/logs.go +++ b/backend/logs.go @@ -6,9 +6,11 @@ import ( "html/template" "io/fs" "log/slog" + "maps" "net/http" "os" "path/filepath" + "slices" "strings" "sync" "time" @@ -112,6 +114,7 @@ func readLogDir(path string, dir []os.DirEntry) error { } } wg.Wait() + sortLogs() return nil } @@ -123,7 +126,11 @@ func HandleLogs(r *chi.Mux) { } func handleLogList(w http.ResponseWriter, r *http.Request) { - + d := handleGenericLogsDisplay(w, r) + if d == nil { + return + } + d.handleGeneric(w, r, "home_log", d) } func handleLog(w http.ResponseWriter, r *http.Request) { @@ -187,3 +194,17 @@ func parseLog(d *logData, path, slug string, fi fs.FileInfo) bool { logs[path] = d return true } + +func sortLogs() { + sortedLogs = slices.SortedFunc(maps.Values(logs), func(l *logData, l2 *logData) int { + lt := l.ModAt + l2t := l2.ModAt + // we want it reversed + if lt.Before(l2t) { + return 1 + } else if lt.After(l2t) { + return -1 + } + return 0 + }) +} |
