forked from thecodingmachine/gotenberg-go-client
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhtml.go
More file actions
78 lines (61 loc) 路 1.67 KB
/
Copy pathhtml.go
File metadata and controls
78 lines (61 loc) 路 1.67 KB
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
70
71
72
73
74
75
76
77
78
package gotenberg
import (
"github.com/starwalkn/gotenberg-go-client/v8/document"
)
const (
endpointHTMLConvert = "/forms/chromium/convert/html"
endpointHTMLScreenshot = "/forms/chromium/screenshot/html"
)
// HTMLRequest facilitates HTML conversion with the Gotenberg API.
type HTMLRequest struct {
index document.Document
assets []document.Document
embeds []document.Document
*chromiumRequest
}
func NewHTMLRequest(index document.Document) *HTMLRequest {
return &HTMLRequest{
index: index,
assets: []document.Document{},
embeds: []document.Document{},
chromiumRequest: newChromiumRequest(),
}
}
func (req *HTMLRequest) endpoint() string {
return endpointHTMLConvert
}
func (req *HTMLRequest) screenshotEndpoint() string {
return endpointHTMLScreenshot
}
func (req *HTMLRequest) formDocuments() map[string]document.Document {
files := make(map[string]document.Document)
files["index.html"] = req.index
if req.header != nil {
files["header.html"] = req.header
}
if req.footer != nil {
files["footer.html"] = req.footer
}
for _, asset := range req.assets {
files[asset.Filename()] = asset
}
return files
}
func (req *HTMLRequest) formEmbeds() map[string]document.Document {
embeds := make(map[string]document.Document)
for _, embed := range req.embeds {
embeds[embed.Filename()] = embed
}
return embeds
}
func (req *HTMLRequest) Embeds(docs ...document.Document) {
req.embeds = docs
}
// Assets sets assets form files.
func (req *HTMLRequest) Assets(assets ...document.Document) {
req.assets = assets
}
// Compile-time checks to ensure type implements desired interfaces.
var (
_ = MultipartRequest(new(HTMLRequest))
)