From f2f76d48f5528ad7a1e5f1f675d2971e2fbcae09 Mon Sep 17 00:00:00 2001 From: sanloublues Date: Fri, 25 Jan 2019 16:31:04 -0500 Subject: [PATCH 1/2] fixes mailhog/MailHog#166 Uses go 1.8 function sort.Slice --- api/v2.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/v2.go b/api/v2.go index 4ef0c40..5ddcb72 100644 --- a/api/v2.go +++ b/api/v2.go @@ -4,6 +4,7 @@ import ( "encoding/json" "net/http" "strconv" + "sort" "github.com/gorilla/pat" "github.com/ian-kent/go-log/log" @@ -115,6 +116,11 @@ func (apiv2 *APIv2) messages(w http.ResponseWriter, req *http.Request) { res.Items = []data.Message(*messages) res.Total = apiv2.config.Storage.Count() + log.Println("Attempting sort") + sort.Slice(res.Items, func(i, j int) bool{ + return res.Items[i].Created.After(res.Items[j].Created) + }) + bytes, _ := json.Marshal(res) w.Header().Add("Content-Type", "text/json") w.Write(bytes) From 7c385c8a31ea4fc42ceb36cf54f49a1c10ddf256 Mon Sep 17 00:00:00 2001 From: sanloublues Date: Fri, 25 Jan 2019 16:33:16 -0500 Subject: [PATCH 2/2] remove dev log statement --- api/v2.go | 1 - 1 file changed, 1 deletion(-) diff --git a/api/v2.go b/api/v2.go index 5ddcb72..02ed795 100644 --- a/api/v2.go +++ b/api/v2.go @@ -116,7 +116,6 @@ func (apiv2 *APIv2) messages(w http.ResponseWriter, req *http.Request) { res.Items = []data.Message(*messages) res.Total = apiv2.config.Storage.Count() - log.Println("Attempting sort") sort.Slice(res.Items, func(i, j int) bool{ return res.Items[i].Created.After(res.Items[j].Created) })