-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgotenberg.go
More file actions
52 lines (42 loc) · 1.49 KB
/
gotenberg.go
File metadata and controls
52 lines (42 loc) · 1.49 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
// Package gotenberg provides a client for the Gotenberg service.
// It offers a convenient API for document conversion using various engines.
package gotenberg
import (
"net/http"
"github.com/nativebpm/gotenberg/internal/chromium"
"github.com/nativebpm/gotenberg/internal/gotenberg"
"github.com/nativebpm/gotenberg/internal/libreoffice"
"github.com/nativebpm/gotenberg/internal/pdfengines"
"github.com/nativebpm/connectors/httpstream"
)
// Re-export common types for easier access.
type Response = gotenberg.Response
// Client is a Gotenberg HTTP client that wraps the base HTTP client
// with Gotenberg-specific functionality for document conversion.
type Client struct {
HttpStream *httpstream.Client
}
// NewClient creates a new Gotenberg client with the given HTTP client and base URL.
// Returns an error if the base URL is invalid.
func NewClient(httpClient *http.Client, baseURL string) (*Client, error) {
client, err := httpstream.NewClient(httpClient, baseURL)
if err != nil {
return nil, err
}
return &Client{
HttpStream: client,
}, nil
}
func (c *Client) Use(middleware func(http.RoundTripper) http.RoundTripper) *Client {
c.HttpStream = c.HttpStream.Use(middleware)
return c
}
func (c *Client) Chromium() *chromium.Chromium {
return chromium.NewChromium(c.HttpStream)
}
func (c *Client) LibreOffice() *libreoffice.LibreOffice {
return libreoffice.NewLibreOffice(c.HttpStream)
}
func (c *Client) PDFEngines() *pdfengines.PDFEngines {
return pdfengines.NewPDFEngines(c.HttpStream)
}