-
Notifications
You must be signed in to change notification settings - Fork 1
/
paging.go
42 lines (37 loc) · 903 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
package linkedin
import (
"strings"
)
// Paging struct for pagination
type Paging struct {
Start int `json:"start"`
Count int `json:"count"`
Links []Link `json:"links"`
Total int `json:"total"`
}
// Link struct for pagination
type Link struct {
Type string `json:"type"` // application/json
Rel string `json:"rel"` // prev, next
Href string `json:"href"`
}
// GetNext returns the next page URL
func (p *Paging) GetNext() (bool, string) {
for _, link := range p.Links {
if link.Rel == "next" {
// remove "/rest" from the URL
return true, strings.Replace(link.Href, "/rest", "", 1)
}
}
return false, ""
}
// GetPrev returns the previous page URL
func (p *Paging) GetPrev() (bool, string) {
for _, link := range p.Links {
if link.Rel == "prev" {
// remove "/rest" from the URL
return true, strings.Replace(link.Href, "/rest", "", 1)
}
}
return false, ""
}