27 Star 109 Fork 24

MJ PC Lab/go-http-file-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sortState.go 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
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)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mjpclab/go-http-file-server.git
git@gitee.com:mjpclab/go-http-file-server.git
mjpclab
go-http-file-server
go-http-file-server
v1.15.1

搜索帮助