diff options
| author | Guillermo Serrahima <dev@vylion.com> | 2026-03-21 03:17:46 +0100 |
|---|---|---|
| committer | Guillermo Serrahima <dev@vylion.com> | 2026-03-21 03:17:46 +0100 |
| commit | 75f6db76bdbf8846b58d86951e0bebf8bd4b8a3a (patch) | |
| tree | 3094f6fef1ad34b4b29243e8788342aeb2ba5775 | |
| parent | 6c0d1e1419fedf52477f0bed618d7b08a3ff4cd9 (diff) | |
| download | llostre-75f6db76bdbf8846b58d86951e0bebf8bd4b8a3a.tar.xz llostre-75f6db76bdbf8846b58d86951e0bebf8bd4b8a3a.zip | |
sorted posts chronologically
| -rw-r--r-- | backend/main.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/backend/main.go b/backend/main.go index c7a463e..eb6d70b 100644 --- a/backend/main.go +++ b/backend/main.go @@ -9,6 +9,7 @@ import ( "net/http" "net/url" "os" + "sort" "strings" "sync" "time" @@ -311,6 +312,10 @@ func postsHandler(w http.ResponseWriter, r *http.Request) { return } + sort.Slice(posts, func(i, j int) bool { + return posts[i].CreatedAt.After(posts[j].CreatedAt) + }) + logger.Debug("successfully fetched posts", "number", len(posts)) w.Header().Set("Access-Control-Allow-Origin", "*") |
