diff options
Diffstat (limited to 'scanIterator.go')
| -rw-r--r-- | scanIterator.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/scanIterator.go b/scanIterator.go index 4214014..7f347b2 100644 --- a/scanIterator.go +++ b/scanIterator.go @@ -3,6 +3,7 @@ package repolist import ( "fmt" "os" + "sort" ) type RepoIterator struct { @@ -52,6 +53,22 @@ func (r *RepoList) ReposAll() *RepoIterator { return iterator } +func (r *RepoList) ReposSortByName() *RepoIterator { + repoPointers := r.selectRepoAll() + + sort.Sort(ByName(repoPointers)) + + iterator := NewRepoIterator(repoPointers) + + return iterator +} + +type ByName []*RepoRow + +func (a ByName) Len() int { return len(a) } +func (a ByName) Less(i, j int) bool { return a[i].GoPath() < a[j].GoPath() } +func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + // SelectRepoPointers safely returns a slice of pointers to Repo records. func (r *RepoList) selectRepoAll() []*RepoRow { r.RLock() @@ -67,7 +84,7 @@ func (r *RepoList) selectRepoAll() []*RepoRow { if repo.Status == nil { continue } - if ! repo.Status.InitOk { + if !repo.Status.InitOk { continue } repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration |
