api

package
v8.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package api provides a module which manages a LibreOffice instance and interacts with it via the UNO (Universal Network Objects) API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPdfFormats happens if the PDF formats option cannot be handled
	// by LibreOffice.
	ErrInvalidPdfFormats = errors.New("invalid PDF formats")

	// ErrMalformedPageRanges happens if the page ranges option cannot be
	// interpreted by LibreOffice.
	ErrMalformedPageRanges = errors.New("page ranges are malformed")
)

Functions

This section is empty.

Types

type Api

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

Api is a module which provides a Uno to interact with LibreOffice.

func (*Api) Checks

func (a *Api) Checks() ([]health.CheckerOption, error)

Checks adds a health check that verifies if LibreOffice is healthy.

func (*Api) Descriptor

func (a *Api) Descriptor() gotenberg.ModuleDescriptor

Descriptor returns a Api's module descriptor.

func (*Api) Extensions

func (a *Api) Extensions() []string

Extensions returns the file extensions available for conversions. FIXME: don't care, take all on the route level?

func (*Api) LibreOffice

func (a *Api) LibreOffice() (Uno, error)

LibreOffice returns a Uno for interacting with LibreOffice.

func (*Api) Metrics

func (a *Api) Metrics() ([]gotenberg.Metric, error)

Metrics returns the metrics.

func (*Api) Pdf

func (a *Api) Pdf(ctx context.Context, logger *zap.Logger, inputPath, outputPath string, options Options) error

Pdf converts a document to PDF.

func (*Api) Provision

func (a *Api) Provision(ctx *gotenberg.Context) error

Provision sets the module properties.

func (*Api) Ready

func (a *Api) Ready() error

Ready returns no error if the module is ready.

func (*Api) Start

func (a *Api) Start() error

Start does nothing if auto-start is not enabled. Otherwise, it starts a LibreOffice instance.

func (*Api) StartupMessage

func (a *Api) StartupMessage() string

StartupMessage returns a custom startup message.

func (*Api) Stop

func (a *Api) Stop(ctx context.Context) error

Stop stops the current browser instance.

func (*Api) Validate

func (a *Api) Validate() error

Validate validates the module properties.

type ApiMock

type ApiMock struct {
	PdfMock        func(ctx context.Context, logger *zap.Logger, inputPath, outputPath string, options Options) error
	ExtensionsMock func() []string
}

ApiMock is a mock for the Uno interface.

func (*ApiMock) Extensions

func (api *ApiMock) Extensions() []string

func (*ApiMock) Pdf

func (api *ApiMock) Pdf(ctx context.Context, logger *zap.Logger, inputPath, outputPath string, options Options) error

type Options

type Options struct {
	// Landscape allows to change the orientation of the resulting PDF.
	// Optional.
	Landscape bool

	// PageRanges allows to select the pages to convert.
	// Optional.
	PageRanges string

	// PdfFormats allows to convert the resulting PDF to PDF/A-1b, PDF/A-2b,
	// PDF/A-3b and PDF/UA.
	// Optional.
	PdfFormats gotenberg.PdfFormats
}

Options gathers available options when converting a document to PDF.

type Provider

type Provider interface {
	LibreOffice() (Uno, error)
}

Provider is a module interface which exposes a method for creating a Uno for other modules.

func (m *YourModule) Provision(ctx *gotenberg.Context) error {
	provider, _ := ctx.Module(new(libreofficeapi.Provider))
	libreOffice, _      := provider.(api.Provider).LibreOffice()
}

type ProviderMock

type ProviderMock struct {
	LibreOfficeMock func() (Uno, error)
}

ProviderMock is a mock for the Provider interface.

func (*ProviderMock) LibreOffice

func (provider *ProviderMock) LibreOffice() (Uno, error)

type Uno

type Uno interface {
	Pdf(ctx context.Context, logger *zap.Logger, inputPath, outputPath string, options Options) error
	Extensions() []string
}

Uno is an abstraction on top of the Universal Network Objects API.

Jump to

Keyboard shortcuts

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