forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paging.go
49 lines (40 loc) · 1 KB
/
paging.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
package influxdb
import (
"strconv"
)
const (
DefaultPageSize = 20
MaxPageSize = 100
)
// PagingFilter represents a filter containing url query params.
type PagingFilter interface {
// QueryParams returns a map containing url query params.
QueryParams() map[string][]string
}
// PagingLinks represents paging links.
type PagingLinks struct {
Prev string `json:"prev,omitempty"`
Self string `json:"self"`
Next string `json:"next,omitempty"`
}
// FindOptions represents options passed to all find methods with multiple results.
type FindOptions struct {
Limit int
Offset int
SortBy string
Descending bool
}
// QueryParams returns a map containing url query params.
func (f FindOptions) QueryParams() map[string][]string {
qp := map[string][]string{
"offset": {strconv.Itoa(f.Offset)},
"descending": {strconv.FormatBool(f.Descending)},
}
if f.Limit > 0 {
qp["limit"] = []string{strconv.Itoa(f.Limit)}
}
if f.SortBy != "" {
qp["sortBy"] = []string{f.SortBy}
}
return qp
}