package gitpb import "sort" func (x *Repos) SortByAge() *RepoScanner { // copy the pointers as fast as possible. things := x.selectAllRepos() // todo: try slices.SortFunc() instead to see what happens sort.Sort(sortReposAge(things)) // slices.SortFunc(things, func(a, b *Repos) bool { // return a.Namespace < b.Namespace // Sort by ??. let the compiler work it out?? // }) return newRepoScanner(things) } type sortReposAge []*Repo func (a sortReposAge) Len() int { return len(a) } // sorts in ? order func (r sortReposAge) Less(i, j int) bool { if r[i].NewestAge() > r[j].NewestAge() { return true } return false } func (a sortReposAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }