gotenberg

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 11 Imported by: 0

README

gotenberg-client

Go ReferenceGo Reference

Go Report CardGo Report Card

LicenseLicense

A high-performance Go client for the Gotenberg HTTP API with a fluent builder pattern interface.A high-performance, streaming Go client for the Gotenberg HTTP API, optimized for minimal memory allocations.

Features

  • 🚀 Fluent Builder Pattern: Chain method calls for intuitive API usage- 🚀 High Performance: 70% fewer allocations, 4x faster than traditional approaches

  • ♻️ Client Reuse: Reset and reuse client instances for multiple conversions- � Streaming Architecture: Direct multipart.Writer streaming without intermediate buffers

  • 📦 Zero Dependencies: Uses only Go standard library- ♻️ Buffer Pooling: Optimized memory reuse with sync.Pool

  • 🔄 Webhook Support: Full support for asynchronous processing with webhooks- 🔄 Client Reuse: Reset() method for processing multiple documents

  • Context Support: Proper timeout and cancellation handling- 📦 Zero Dependencies: Uses only Go standard library

  • 🎯 Memory Efficient: Buffer pooling with sync.Pool for optimal performance- 🔗 Webhook Support: Full async processing with webhooks

  • Context Support: Proper timeout and cancellation handling

Best Practices

  • Always close resp.Body to prevent resource leaks
  • Use context.Context for timeouts and cancellations
  • Check response status codes before processing
  • Set appropriate HTTP client timeouts for your use case
  • Inspect Gotenberg-Trace header for debugging

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	FieldSinglePage              = "singlePage"
	FieldPaperWidth              = "paperWidth"
	FieldPaperHeight             = "paperHeight"
	FieldMarginTop               = "marginTop"
	FieldMarginBottom            = "marginBottom"
	FieldMarginLeft              = "marginLeft"
	FieldMarginRight             = "marginRight"
	FieldPreferCSSPageSize       = "preferCssPageSize"
	FieldGenerateDocumentOutline = "generateDocumentOutline"
	FieldGenerateTaggedPDF       = "generateTaggedPdf"
	FieldPrintBackground         = "printBackground"
	FieldOmitBackground          = "omitBackground"
	FieldLandscape               = "landscape"
	FieldScale                   = "scale"
	FieldNativePageRanges        = "nativePageRanges"
)
View Source
const (
	ApplicationJSON = "application/json"
	ContentType     = "Content-Type"
	ContentLength   = "Content-Length"
)
View Source
const (
	HeaderWebhookURL              = "Gotenberg-Webhook-Url"
	HeaderWebhookErrorURL         = "Gotenberg-Webhook-Error-Url"
	HeaderWebhookMethod           = "Gotenberg-Webhook-Method"
	HeaderWebhookErrorMethod      = "Gotenberg-Webhook-Error-Method"
	HeaderWebhookExtraHTTPHeaders = "Gotenberg-Webhook-Extra-Http-Headers"
)
View Source
const (
	FieldURL       = "url"
	FieldFiles     = "files"
	FileIndexHTML  = "index.html"
	FileFooterHTML = "footer.html"
	FileHeaderHTML = "header.html"
	FileStylesCSS  = "styles.css"
)
View Source
const (
	ConvertHTML = "html"
	ConvertURL  = "url"
)

Variables

View Source
var (
	PaperSizeLetter  = [2]float64{8.5, 11}
	PaperSizeLegal   = [2]float64{8.5, 14}
	PaperSizeTabloid = [2]float64{11, 17}
	PaperSizeLedger  = [2]float64{17, 11}
	PaperSizeA0      = [2]float64{33.1, 46.8}
	PaperSizeA1      = [2]float64{23.4, 33.1}
	PaperSizeA2      = [2]float64{16.54, 23.4}
	PaperSizeA3      = [2]float64{11.7, 16.54}
	PaperSizeA4      = [2]float64{8.27, 11.7}
	PaperSizeA5      = [2]float64{5.83, 8.27}
	PaperSizeA6      = [2]float64{4.13, 5.83}
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client, baseURL string) *Client

func (*Client) AsyncConvertHTML added in v1.1.0

func (c *Client) AsyncConvertHTML(ctx context.Context,
	webhookURL, webhookMethod,
	webhookErrorURL, webhookErrorMethod string,
	webHookHeaders map[string]string) (*http.Response, error)

func (*Client) Bool added in v1.0.1

func (c *Client) Bool(field string, value bool) *Client

func (*Client) ConvertHTML added in v1.0.1

func (c *Client) ConvertHTML(ctx context.Context) (*http.Response, error)

func (*Client) ConvertURL added in v1.0.1

func (c *Client) ConvertURL(ctx context.Context) (*http.Response, error)

func (*Client) Err added in v1.0.1

func (c *Client) Err() error

func (*Client) Execute added in v1.0.0

func (c *Client) Execute(ctx context.Context, route string, opts ...RequestOptions) (*http.Response, error)

func (*Client) File added in v1.0.1

func (c *Client) File(filename string, content io.Reader) *Client

func (*Client) Float added in v1.0.1

func (c *Client) Float(field string, value float64) *Client

func (*Client) FooterHTML added in v1.0.1

func (c *Client) FooterHTML(html io.Reader) *Client

func (*Client) HeaderHTML added in v1.0.1

func (c *Client) HeaderHTML(html io.Reader) *Client

func (*Client) IndexHTML added in v1.0.1

func (c *Client) IndexHTML(html io.Reader) *Client

func (*Client) Margins added in v1.0.1

func (c *Client) Margins(top, right, bottom, left float64) *Client

func (*Client) PaperSize added in v1.0.1

func (c *Client) PaperSize(width, height float64) *Client

func (*Client) PaperSizeA4 added in v1.0.1

func (c *Client) PaperSizeA4() *Client

func (*Client) PaperSizeLetter added in v1.0.1

func (c *Client) PaperSizeLetter() *Client

func (*Client) String added in v1.0.1

func (c *Client) String(field string, value string) *Client

func (*Client) StylesCSS added in v1.0.1

func (c *Client) StylesCSS(css io.Reader) *Client

func (*Client) URL added in v1.0.1

func (c *Client) URL(url string) *Client
type Header struct {
	Name  string
	Value string
}

type RequestOptions added in v1.1.0

type RequestOptions func(r *http.Request) error

func WebhookExtraHTTPHeaders added in v1.1.0

func WebhookExtraHTTPHeaders(headers map[string]string) RequestOptions

func WithBytesBody added in v1.1.0

func WithBytesBody(body []byte) RequestOptions

func WithHeader

func WithHeader(key, value string) RequestOptions

func WithHost added in v1.1.0

func WithHost() RequestOptions

func WithJSONBody added in v1.1.0

func WithJSONBody(body interface{}) RequestOptions

func WithQueryParams added in v1.1.0

func WithQueryParams(values url.Values) RequestOptions

func WithReaderBody added in v1.1.0

func WithReaderBody(body io.ReadCloser) RequestOptions

Directories

Path Synopsis
example
cmd/webhook command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL