Use method chaining for searches

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-05-16 21:46:16 -04:00
parent 9d8e731294
commit eda947f6b5
4 changed files with 278 additions and 203 deletions
+52 -14
View File
@@ -17,18 +17,8 @@ const (
kindMode = "more"
)
type sort int
const (
sortHot sort = iota
sortBest
sortNew
sortRising
sortControversial
sortTop
sortRelevance
sortComments
)
// Sort is a sorting option.
type Sort int
var sorts = [...]string{
"hot",
@@ -37,12 +27,60 @@ var sorts = [...]string{
"rising",
"controversial",
"top",
// for search queries
"relevance",
"comments",
}
// Different sorting options.
const (
SortHot Sort = iota
SortBest
SortNew
SortRising
SortControversial
SortTop
SortRelevance
SortComments
)
func (s Sort) String() string {
if s < SortHot || s > SortComments {
return ""
}
return sorts[s]
}
// Timespan is a timespan option.
// E.g. "hour" means in the last hour, "all" means all-time.
// It is used when conducting searches.
type Timespan int
var timespans = [...]string{
"hour",
"day",
"week",
"month",
"year",
"all",
}
// Different timespan options.
const (
TimespanHour Timespan = iota
TimespanDay
TimespanWeek
TimespanMonth
TimespanYear
TimespanAll
)
func (t Timespan) String() string {
if t < TimespanHour || t > TimespanAll {
return ""
}
return timespans[t]
}
type sticky int
const (