-
Notifications
You must be signed in to change notification settings - Fork 154
/
link_page.go
49 lines (37 loc) · 1.02 KB
/
link_page.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 httphelper
import (
"log"
"github.com/jmespath/go-jmespath"
"github.com/chnsz/golangsdk/pagination"
)
type LinkPager struct {
pagination.LinkedPageBase
uuid string
DataPath string
LinkExp string
}
// IsEmpty returns true if an ImagePage contains no Image results.
func (p LinkPager) IsEmpty() (bool, error) {
rst, err := bodyToGJson(p.Body)
if err != nil {
return false, err
}
count := len(rst.Get(p.DataPath).Array())
log.Printf("[DEBUG] [LinkPager] [%v] response count: %v, dataPath: %s", p.uuid, count, p.DataPath)
return count == 0, nil
}
// NextPageURL uses the response's embedded link reference to navigate to the
// next page of results.
func (p LinkPager) NextPageURL() (string, error) {
rst, err := bodyToGJson(p.Body)
if err != nil {
return "", err
}
val, err := jmespath.Search(p.LinkExp, rst.Value())
log.Printf("[DEBUG] [LinkPager] [%v] NextPageURL: %v, LinkExp: %s, error: %v", p.uuid, val, p.LinkExp, err)
if err != nil {
return "", err
}
link, _ := val.(string)
return link, nil
}