Skip to content

Commit

Permalink
Sort images by UpdatedAt before finding latest
Browse files Browse the repository at this point in the history
  • Loading branch information
nlopes committed Sep 11, 2017
1 parent c9feef4 commit 70ae8d2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
"reflect"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -79,11 +80,15 @@ func (c Client) GetLatestImage() (models.Image, error) {
return image, err
}

if len(images) > 0 {
for i := len(images) - 1; i >= 0; i-- {
if images[i].Ready {
return images[i], nil
}
// Make sure they are all sorted by UpdatedAt
// The most up to date should be the first of the slice
sort.Slice(images, func(i, j int) bool {
return images[i].UpdatedAt.After(images[j].UpdatedAt)
})

for _, image := range images {
if image.Ready {
return image, nil
}
}

Expand Down

0 comments on commit 70ae8d2

Please sign in to comment.