-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpage.go
69 lines (65 loc) · 1.54 KB
/
webpage.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
package labstack
import (
"github.com/go-resty/resty/v2"
"github.com/labstack/labstack-go/webpage"
"strconv"
)
type (
WebpageService struct {
resty *resty.Client
}
)
func (w *WebpageService) Image(req *webpage.ImageRequest) (*webpage.ImageResponse, error) {
res := new(webpage.ImageResponse)
err := new(Error)
r, e := w.resty.R().
SetQueryParams(map[string]string{
"url": req.URL,
"language": req.Language,
"ttl": strconv.Itoa(req.TTL),
"full_page": strconv.FormatBool(req.FullPage),
"retina": strconv.FormatBool(req.Retina),
"width": strconv.Itoa(req.Width),
"height": strconv.Itoa(req.Height),
"delay": strconv.Itoa(req.Delay),
}).
SetResult(res).
SetError(err).
Get("/image")
if e != nil {
return nil, &Error{
Message: err.Error(),
}
}
if isError(r.StatusCode()) {
return nil, err
}
return res, nil
}
func (w *WebpageService) PDF(req *webpage.PDFRequest) (*webpage.PDFResponse, error) {
res := new(webpage.PDFResponse)
err := new(Error)
r, e := w.resty.R().
SetQueryParams(map[string]string{
"url": req.URL,
"language": req.Language,
"ttl": strconv.Itoa(req.TTL),
"size": req.Size,
"width": strconv.Itoa(req.Width),
"height": strconv.Itoa(req.Height),
"orientation": req.Orientation,
"delay": strconv.Itoa(req.Delay),
}).
SetResult(res).
SetError(err).
Get("/pdf")
if e != nil {
return nil, &Error{
Message: err.Error(),
}
}
if isError(r.StatusCode()) {
return nil, err
}
return res, nil
}