代码拉取完成,页面将自动刷新
package serverHandler
type dirSort int
const (
dirSortFirst dirSort = -1
dirSortMixed dirSort = 0
dirSortLast dirSort = 1
)
const (
nameAsc byte = 'n'
nameDesc byte = 'N'
typeAsc byte = 'e'
typeDesc byte = 'E'
sizeAsc byte = 's'
sizeDesc byte = 'S'
timeAsc byte = 't'
timeDesc byte = 'T'
)
type SortState struct {
dirSort dirSort
key byte
}
func (info SortState) DirSort() dirSort {
return info.dirSort
}
func (info SortState) Key() string {
return string(info.key)
}
func (info SortState) mergeDirWithKey(key byte) string {
switch info.dirSort {
case dirSortFirst:
return "/" + string(key)
case dirSortLast:
return string(key) + "/"
default:
return string(key)
}
}
func (info SortState) CurrentSort() string {
return info.mergeDirWithKey(info.key)
}
func (info SortState) NextDirSort() string {
switch info.dirSort {
case dirSortFirst: // next is dirSortLast
return string(info.key) + "/"
case dirSortLast: // next is dirSortMixed
return string(info.key)
case dirSortMixed: // next is dirSortFirst
return "/" + string(info.key)
}
return "/" + string(info.key)
}
func (info SortState) NextNameSort() string {
var nextKey byte
switch info.key {
case nameAsc:
nextKey = nameDesc
default:
nextKey = nameAsc
}
return info.mergeDirWithKey(nextKey)
}
func (info SortState) NextTypeSort() string {
var nextKey byte
switch info.key {
case typeAsc:
nextKey = typeDesc
default:
nextKey = typeAsc
}
return info.mergeDirWithKey(nextKey)
}
func (info SortState) NextSizeSort() string {
var nextKey byte
switch info.key {
case sizeDesc:
nextKey = sizeAsc
default:
nextKey = sizeDesc
}
return info.mergeDirWithKey(nextKey)
}
func (info SortState) NextTimeSort() string {
var nextKey byte
switch info.key {
case timeDesc:
nextKey = timeAsc
default:
nextKey = timeDesc
}
return info.mergeDirWithKey(nextKey)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。