mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-15 20:02:15 +01:00
4.0.0 (#42)
* adding URL conversions * updating gotenberg version in documentation * pkg: input as variadic string (#39) * pkg: input as variadic string * pkg: fix link to github doc * update doc about v4 client * make doc * fixing missing variadic inputs in doc * adding more fonts * updating PHP documentation
This commit is contained in:
85
pkg/url.go
Normal file
85
pkg/url.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package gotenberg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// URLRequest facilitates remote URL conversion
|
||||
// with the Gotenberg API.
|
||||
type URLRequest struct {
|
||||
headerFilePath string
|
||||
footerFilePath string
|
||||
values map[string]string
|
||||
}
|
||||
|
||||
// NewURLRequest create URLRequest.
|
||||
func NewURLRequest(URL string) *URLRequest {
|
||||
req := &URLRequest{values: make(map[string]string)}
|
||||
req.values[remoteURL] = URL
|
||||
return req
|
||||
}
|
||||
|
||||
// SetWebhookURL sets webhookURL form field.
|
||||
func (url *URLRequest) SetWebhookURL(webhookURL string) {
|
||||
url.values[webhookURL] = webhookURL
|
||||
}
|
||||
|
||||
// SetHeader sets header form file.
|
||||
func (url *URLRequest) SetHeader(fpath string) error {
|
||||
if !fileExists(fpath) {
|
||||
return fmt.Errorf("%s: header file does not exist", fpath)
|
||||
}
|
||||
url.headerFilePath = fpath
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetFooter sets footer form file.
|
||||
func (url *URLRequest) SetFooter(fpath string) error {
|
||||
if !fileExists(fpath) {
|
||||
return fmt.Errorf("%s: footer file does not exist", fpath)
|
||||
}
|
||||
url.footerFilePath = fpath
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetPaperSize sets paperWidth and paperHeight form fields.
|
||||
func (url *URLRequest) SetPaperSize(size [2]float64) {
|
||||
url.values[paperWidth] = fmt.Sprintf("%f", size[0])
|
||||
url.values[paperHeight] = fmt.Sprintf("%f", size[1])
|
||||
}
|
||||
|
||||
// SetMargins sets marginTop, marginBottom,
|
||||
// marginLeft and marginRight form fields.
|
||||
func (url *URLRequest) SetMargins(margins [4]float64) {
|
||||
url.values[marginTop] = fmt.Sprintf("%f", margins[0])
|
||||
url.values[marginBottom] = fmt.Sprintf("%f", margins[1])
|
||||
url.values[marginLeft] = fmt.Sprintf("%f", margins[2])
|
||||
url.values[marginRight] = fmt.Sprintf("%f", margins[3])
|
||||
}
|
||||
|
||||
// SetLandscape sets landscape form field.
|
||||
func (url *URLRequest) SetLandscape(isLandscape bool) {
|
||||
url.values[landscape] = strconv.FormatBool(isLandscape)
|
||||
}
|
||||
|
||||
func (url *URLRequest) getPostURL() string {
|
||||
return "/convert/url"
|
||||
}
|
||||
|
||||
func (url *URLRequest) getFormValues() map[string]string {
|
||||
return url.values
|
||||
}
|
||||
|
||||
func (url *URLRequest) getFormFiles() map[string]string {
|
||||
files := make(map[string]string)
|
||||
files["header.html"] = url.headerFilePath
|
||||
files["footer.html"] = url.footerFilePath
|
||||
return files
|
||||
}
|
||||
|
||||
// Compile-time checks to ensure type implements desired interfaces.
|
||||
var (
|
||||
_ = Request(new(URLRequest))
|
||||
_ = ChromeRequest(new(URLRequest))
|
||||
)
|
||||
Reference in New Issue
Block a user