package common
import (
"strconv"
"strings"
)
type Status uint8
const (
ShowAll Status = iota
FilterRemakes
Trusted
APlus
func (st *Status) Parse(s string) {
switch s {
case "1":
*st = FilterRemakes
break
case "2":
*st = Trusted
case "3":
*st = APlus
default:
*st = ShowAll
}
type SortMode uint8
ID SortMode = iota
Name
Date
Downloads
Size
Seeders
Leechers
Completed
func (s *SortMode) Parse(str string) {
switch str {
*s = Name
*s = Date
*s = Downloads
case "4":
*s = Size
case "5":
*s = Seeders
case "6":
*s = Leechers
case "7":
*s = Completed
*s = ID
type Category struct {
Main, Sub uint8
func (c Category) String() (s string) {
if c.Main != 0 {
s += strconv.Itoa(int(c.Main))
s += "_"
if c.Sub != 0 {
s += strconv.Itoa(int(c.Sub))
return
func (c Category) IsSet() bool {
return c.Main != 0 && c.Sub != 0
// Parse sets category by string
// returns true if string is valid otherwise returns false
func (c *Category) Parse(s string) (ok bool) {
parts := strings.Split(s, "_")
if len(parts) == 2 {
tmp, err := strconv.ParseUint(parts[0], 10, 8)
if err == nil {
c.Main = uint8(tmp)
tmp, err = strconv.ParseUint(parts[1], 10, 8)
c.Sub = uint8(tmp)
ok = true
// deprecated for TorrentParam
type SearchParam struct {
Order bool // True means acsending
Status Status
Sort SortMode
Category Category
Page int
UserID uint
Max uint
NotNull string
Query string