This repository has been archived by the owner on Sep 26, 2021. It is now read-only.
/
query.go
81 lines (62 loc) · 1.68 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package types
import (
"net/url"
"github.com/dyninc/qstring"
)
// -
// Pagination
// -
// PageSize represents a query page size parameter
type PageSize int
// PageSizeDefault controls the default page size of listings
const PageSizeDefault PageSize = 5000
// -
// Sorting
// -
// SortOrder represents a query result sort order
type SortOrder string
// SortColumn represents a column to sort results by
type SortColumn string
// SortAsc is the ascending sort order for listings
const SortAsc SortOrder = "asc"
// SortDesc is the descending sort order for listings
const SortDesc SortOrder = "desc"
// ByPlayers means the list will use the amount of players as a sort key
const ByPlayers SortColumn = "player"
// -
// Filtering
// -
// FilterAttribute represents a filter to apply to results
type FilterAttribute string
// FilterPassword filters out servers with passwords
const FilterPassword FilterAttribute = "password"
// FilterEmpty filters out empty servers
const FilterEmpty FilterAttribute = "empty"
// FilterFull filters out full servers
const FilterFull FilterAttribute = "full"
// -
// URL Query
// -
// ServerListParams represents the URL query parameters for server listing
type ServerListParams struct {
Page int
PageSize PageSize
Sort SortOrder
By SortColumn
Filters []FilterAttribute
}
// Example returns an example of ServerListParams in url.Values format
func (slp ServerListParams) Example() (result url.Values) {
// nolint
result, err := qstring.Marshal(&ServerListParams{
Page: 2,
PageSize: 100,
Sort: SortAsc,
By: ByPlayers,
Filters: []FilterAttribute{FilterFull, FilterPassword},
})
if err != nil {
panic(err)
}
return
}