ApplySort applies the sort order using .Order and .Sort
()
| 17 | |
| 18 | // ApplySort applies the sort order using .Order and .Sort |
| 19 | func (l Listing) ApplySort() { |
| 20 | // Check '.Order' to know how to sort |
| 21 | if !l.Sorting.Asc { |
| 22 | switch l.Sorting.By { |
| 23 | case "name": |
| 24 | sort.Sort(sort.Reverse(byName(l))) |
| 25 | case "size": |
| 26 | sort.Sort(sort.Reverse(bySize(l))) |
| 27 | case "modified": |
| 28 | sort.Sort(sort.Reverse(byModified(l))) |
| 29 | default: |
| 30 | // If not one of the above, do nothing |
| 31 | return |
| 32 | } |
| 33 | } else { // If we had more Orderings we could add them here |
| 34 | switch l.Sorting.By { |
| 35 | case "name": |
| 36 | sort.Sort(byName(l)) |
| 37 | case "size": |
| 38 | sort.Sort(bySize(l)) |
| 39 | case "modified": |
| 40 | sort.Sort(byModified(l)) |
| 41 | default: |
| 42 | sort.Sort(byName(l)) |
| 43 | return |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Implement sorting for Listing |
| 49 | type byName Listing |
no test coverage detected