sortMethod simplification. (#1535)
* made sortMethod a string enum to reduce comparisons and repetition * main uses sortmethod directly instead of converting it into a string * updated sortmethod validity check to no longer require slices package * Update opts.go Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com> --------- Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>
This commit is contained in:
1 parent
f13325f78d
commit
e1ab72516d
3 files changed
+31
-65
No files matched your search
@@ -5,18 +5,30 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type sortMethod byte
|
||||
// String values match the sortby string sent by the user at startup
|
||||
type sortMethod string
|
||||
|
||||
const (
|
||||
naturalSort sortMethod = iota
|
||||
nameSort
|
||||
sizeSort
|
||||
timeSort
|
||||
atimeSort
|
||||
ctimeSort
|
||||
extSort
|
||||
naturalSort sortMethod = "natural"
|
||||
nameSort sortMethod = "name"
|
||||
sizeSort sortMethod = "size"
|
||||
timeSort sortMethod = "time"
|
||||
atimeSort sortMethod = "atime"
|
||||
ctimeSort sortMethod = "ctime"
|
||||
extSort sortMethod = "ext"
|
||||
)
|
||||
|
||||
func isValidSortMethod(method sortMethod) bool {
|
||||
for _, validMethod := range []sortMethod{naturalSort, nameSort, sizeSort, timeSort, atimeSort, ctimeSort, extSort} {
|
||||
if method == validMethod {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const invalidSortErrorMessage = `sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'ctime' or 'ext'`
|
||||
|
||||
type sortOption byte
|
||||
|
||||
const (
|
||||
|
||||
Reference in new issue
Block a user