-
Notifications
You must be signed in to change notification settings - Fork 145
/
pagination.go
52 lines (42 loc) · 889 Bytes
/
pagination.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
package coinbasepro
import (
"net/url"
"strconv"
)
type PaginationParams struct {
Limit int
Before string
After string
Extra map[string]string
}
func (p *PaginationParams) Encode(direction string) string {
values := url.Values{}
if p.Limit > 0 {
values.Add("limit", strconv.Itoa(p.Limit))
}
if p.Before != "" && direction == "prev" {
values.Add("before", p.Before)
}
if p.After != "" && direction == "next" {
values.Add("after", p.After)
}
for k, v := range p.Extra {
values.Add(k, v)
}
return values.Encode()
}
func (p *PaginationParams) Done(direction string) bool {
if p.Before == "" && direction == "prev" {
return true
}
if p.After == "" && direction == "next" {
return true
}
return false
}
func (p *PaginationParams) AddExtraParam(key, value string) {
if p.Extra == nil {
p.Extra = make(map[string]string)
}
p.Extra[key] = value
}