Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Uses go 1.8 function sort.Slice
  • Loading branch information
matttamatic committed Jan 25, 2019
1 parent 50f74a1 commit f2f76d4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"net/http"
"strconv"
"sort"

"github.com/gorilla/pat"
"github.com/ian-kent/go-log/log"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f2f76d4

Please sign in to comment.