forked from thecodingmachine/gotenberg-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl.go
47 lines (39 loc) · 1.05 KB
/
url.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
package gotenberg
import "fmt"
const (
remoteURL string = "remoteURL"
remoteURLBaseHTTPHeaderKey string = "Gotenberg-Remoteurl-"
)
// URLRequest facilitates remote URL conversion
// with the Gotenberg API.
type URLRequest struct {
*chromeRequest
}
// NewURLRequest create URLRequest.
func NewURLRequest(url string) *URLRequest {
req := &URLRequest{newChromeRequest()}
req.values[remoteURL] = url
return req
}
func (req *URLRequest) postURL() string {
return "/convert/url"
}
// AddRemoteURLHTTPHeader add a remote URL custom HTTP header.
func (req *URLRequest) AddRemoteURLHTTPHeader(key, value string) {
key = fmt.Sprintf("%s%s", remoteURLBaseHTTPHeaderKey, key)
req.httpHeaders[key] = value
}
func (req *URLRequest) formFiles() map[string]Document {
files := make(map[string]Document)
if req.header != nil {
files["header.html"] = req.header
}
if req.footer != nil {
files["footer.html"] = req.footer
}
return files
}
// Compile-time checks to ensure type implements desired interfaces.
var (
_ = Request(new(URLRequest))
)