-
Notifications
You must be signed in to change notification settings - Fork 0
/
paging.go
44 lines (35 loc) · 1002 Bytes
/
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
package banking
const (
// DefaultPageSize is the elements count that will be placed on the single response page if option was not
// specified.
DefaultPageSize = 20
// MaxPageSize is the maximum elements count that could be placed on the single response page.
MaxPageSize = 100
)
// FindOptions represents options passed to all find methods with multiple results.
type FindOptions struct {
limit uint64
offset uint64
}
// NewFindOptions returns a new FindOptions instance.
func NewFindOptions(limit, offset uint64) FindOptions {
opts := FindOptions{
limit: limit,
offset: offset,
}
if opts.limit == 0 {
opts.limit = DefaultPageSize
}
if opts.limit > MaxPageSize {
opts.limit = MaxPageSize
}
return opts
}
// Limit is the elements count that could be placed on the single response page.
func (opts FindOptions) Limit() uint64 {
return opts.limit
}
// Offset is the elements count that should be skipped.
func (opts FindOptions) Offset() uint64 {
return opts.offset
}