Remove sort interface
This commit is contained in:
parent
cb0ffa3497
commit
e08a3cf14a
24
main.go
24
main.go
@ -15,9 +15,11 @@ import (
|
||||
dockerClient "github.com/docker/docker/client"
|
||||
)
|
||||
|
||||
// Default values for fetching tags from registry
|
||||
var registryBase = "https://registry.hub.docker.com"
|
||||
var maxPages = 10
|
||||
|
||||
// Regexp used to extract tag information
|
||||
var tagRegexp = regexp.MustCompile(`(.*):[vV]{0,1}([0-9.]+)(-(.*)){0,1}`)
|
||||
|
||||
// ImageTag is wraps an image and tag values for a container
|
||||
@ -93,24 +95,6 @@ func ParseImageTag(imageTag string) (ImageTag, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ImageTagSort is an interface for sorting ImageTags
|
||||
type ImageTagSort []ImageTag
|
||||
|
||||
// Len gives the length of the image sorter interface
|
||||
func (slice ImageTagSort) Len() int {
|
||||
return len(slice)
|
||||
}
|
||||
|
||||
// Less returns true if the first value is less than or equal to the second
|
||||
func (slice ImageTagSort) Less(i, j int) bool {
|
||||
return slice[i].CompareTo(slice[j]) == -1
|
||||
}
|
||||
|
||||
// Swap two values in slice
|
||||
func (slice ImageTagSort) Swap(i, j int) {
|
||||
slice[i], slice[j] = slice[j], slice[i]
|
||||
}
|
||||
|
||||
func getJSON(url string, response interface{}) error {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
@ -177,18 +161,20 @@ func getNewerTags(current ImageTag) ([]ImageTag, error) {
|
||||
}
|
||||
}
|
||||
// Sort tags with newest first
|
||||
sort.Sort(sort.Reverse(ImageTagSort(newerTags)))
|
||||
sort.Slice(newerTags, func(i, j int) bool { return newerTags[i].CompareTo(newerTags[j]) == 1 })
|
||||
return newerTags, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
dockerClient, err := dockerClient.NewClientWithOpts(dockerClient.FromEnv)
|
||||
if err != nil {
|
||||
fmt.Println("Could not initialize docker client")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
containers, err := dockerClient.ContainerList(context.Background(), dockerTypes.ContainerListOptions{})
|
||||
if err != nil {
|
||||
fmt.Println("Could list container from docker client")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user