This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from thecodingmachine/5.0.0
updating for Gotenberg 5.0.0
- Loading branch information
Showing
18 changed files
with
254 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package gotenberg | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
const ( | ||
waitDelay string = "waitDelay" | ||
paperWidth string = "paperWidth" | ||
paperHeight string = "paperHeight" | ||
marginTop string = "marginTop" | ||
marginBottom string = "marginBottom" | ||
marginLeft string = "marginLeft" | ||
marginRight string = "marginRight" | ||
landscapeChrome string = "landscape" | ||
) | ||
|
||
// nolint: gochecknoglobals | ||
var ( | ||
// A3 paper size. | ||
A3 = [2]float64{11.7, 16.5} | ||
// A4 paper size. | ||
A4 = [2]float64{8.27, 11.7} | ||
// A5 paper size. | ||
A5 = [2]float64{5.8, 8.3} | ||
// A6 paper size. | ||
A6 = [2]float64{4.1, 5.8} | ||
// Letter paper size. | ||
Letter = [2]float64{8.5, 11} | ||
// Legal paper size. | ||
Legal = [2]float64{8.5, 14} | ||
// Tabloid paper size. | ||
Tabloid = [2]float64{11, 17} | ||
) | ||
|
||
// nolint: gochecknoglobals | ||
var ( | ||
// NoMargins removes margins. | ||
NoMargins = [4]float64{0, 0, 0, 0} | ||
// NormalMargins uses 1 inche margins. | ||
NormalMargins = [4]float64{1, 1, 1, 1} | ||
// LargeMargins uses 2 inche margins. | ||
LargeMargins = [4]float64{2, 2, 2, 2} | ||
) | ||
|
||
type chromeRequest struct { | ||
headerFilePath string | ||
footerFilePath string | ||
|
||
*request | ||
} | ||
|
||
func newChromeRequest() *chromeRequest { | ||
return &chromeRequest{"", "", newRequest()} | ||
} | ||
|
||
// WaitDelay sets waitDelay form field. | ||
func (req *chromeRequest) WaitDelay(delay float64) { | ||
req.values[waitDelay] = strconv.FormatFloat(delay, 'f', 2, 64) | ||
} | ||
|
||
// Header sets header form file. | ||
func (req *chromeRequest) Header(fpath string) error { | ||
if !fileExists(fpath) { | ||
return fmt.Errorf("%s: header file does not exist", fpath) | ||
} | ||
req.headerFilePath = fpath | ||
return nil | ||
} | ||
|
||
// Footer sets footer form file. | ||
func (req *chromeRequest) Footer(fpath string) error { | ||
if !fileExists(fpath) { | ||
return fmt.Errorf("%s: footer file does not exist", fpath) | ||
} | ||
req.footerFilePath = fpath | ||
return nil | ||
} | ||
|
||
// PaperSize sets paperWidth and paperHeight form fields. | ||
func (req *chromeRequest) PaperSize(size [2]float64) { | ||
req.values[paperWidth] = fmt.Sprintf("%f", size[0]) | ||
req.values[paperHeight] = fmt.Sprintf("%f", size[1]) | ||
} | ||
|
||
// Margins sets marginTop, marginBottom, | ||
// marginLeft and marginRight form fields. | ||
func (req *chromeRequest) Margins(margins [4]float64) { | ||
req.values[marginTop] = fmt.Sprintf("%f", margins[0]) | ||
req.values[marginBottom] = fmt.Sprintf("%f", margins[1]) | ||
req.values[marginLeft] = fmt.Sprintf("%f", margins[2]) | ||
req.values[marginRight] = fmt.Sprintf("%f", margins[3]) | ||
} | ||
|
||
// Landscape sets landscape form field. | ||
func (req *chromeRequest) Landscape(isLandscape bool) { | ||
req.values[landscapeChrome] = strconv.FormatBool(isLandscape) | ||
} | ||
|
||
func (req *chromeRequest) formFiles() map[string]string { | ||
files := make(map[string]string) | ||
files["header.html"] = req.headerFilePath | ||
files["footer.html"] = req.footerFilePath | ||
return files | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
module github.com/thecodingmachine/gotenberg-go-client/v4 | ||
module github.com/thecodingmachine/gotenberg-go-client/v5 | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/stretchr/testify v1.3.0 | ||
github.com/thecodingmachine/gotenberg-go-client/v4 v4.3.1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.