-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathpaging.go
69 lines (59 loc) · 2.08 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2020-2021 InfluxData, Inc. All rights reserved.
// Use of this source code is governed by MIT
// license that can be found in the LICENSE file.
package api
import "github.com/influxdata/influxdb-client-go/v2/domain"
// PagingOption is the function type for applying paging option
type PagingOption func(p *Paging)
// Paging holds pagination parameters for various Get* functions of InfluxDB 2 API
// Not the all options are usable for some Get* functions
type Paging struct {
// Starting offset for returning items
// Default 0.
offset domain.Offset
// Maximum number of items returned.
// Default 0 - not applied
limit domain.Limit
// What field should be used for sorting
sortBy string
// Changes sorting direction
descending domain.Descending
// The last resource ID from which to seek from (but not including).
// This is to be used instead of `offset`.
after domain.After
}
// defaultPagingOptions returns default paging options: offset 0, limit 0 (not applied), default sorting, ascending
func defaultPaging() *Paging {
return &Paging{limit: 0, offset: 0, sortBy: "", descending: false, after: ""}
}
// PagingWithLimit sets limit option - maximum number of items returned.
func PagingWithLimit(limit int) PagingOption {
return func(p *Paging) {
p.limit = domain.Limit(limit)
}
}
// PagingWithOffset set starting offset for returning items. Default 0.
func PagingWithOffset(offset int) PagingOption {
return func(p *Paging) {
p.offset = domain.Offset(offset)
}
}
// PagingWithSortBy sets field name which should be used for sorting
func PagingWithSortBy(sortBy string) PagingOption {
return func(p *Paging) {
p.sortBy = sortBy
}
}
// PagingWithDescending changes sorting direction
func PagingWithDescending(descending bool) PagingOption {
return func(p *Paging) {
p.descending = domain.Descending(descending)
}
}
// PagingWithAfter set after option - the last resource ID from which to seek from (but not including).
// This is to be used instead of `offset`.
func PagingWithAfter(after string) PagingOption {
return func(p *Paging) {
p.after = domain.After(after)
}
}