backend

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoBinary    = errors.New("binary not found")
	ErrNoRoute     = errors.New("no conversion route")
	ErrConvertFail = errors.New("conversion failed")
)
View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is the process-global registry used by existing init()-based backend registration. CLI adapters continue to use this by default.

View Source
var ErrUnsupportedOp = errors.New("unsupported operation")

ErrUnsupportedOp indicates that a processor does not support the requested operation.

Functions

func IsAvailable added in v0.1.1

func IsAvailable(b Backend, from, to string) bool

IsAvailable reports whether `b` can currently perform the from→to capability given the host's installed binaries. The router uses this to exclude unavailable edges at graph-build time so conversions never attempt to invoke a missing binary.

func Register

func Register(b Backend)

Register adds a backend to the global DefaultRegistry. Backends should call Register in their init() or via a constructor.

func RegisterProcessor added in v0.1.1

func RegisterProcessor(p Processor)

RegisterProcessor adds a Processor to the global DefaultRegistry.

func Wrap

func Wrap(name, from, to string, err error) error

Wrap creates a ConvertError.

Types

type Availabler added in v0.1.1

type Availabler interface {
	IsAvailable(from, to string) bool
}

Availabler is an optional interface a Backend may implement to declare, per-capability, whether the underlying tooling is currently installed. Backends with multiple edge-specific binaries (e.g. csvkit uses in2csv/xlsx2csv for xlsx→csv but csvjson for csv→json) should implement this so the router can filter out edges that cannot actually run.

If a backend does not implement Availabler, IsAvailable falls back to checking whether BinaryName() is present in $PATH.

type Backend

type Backend interface {
	Name() string
	BinaryName() string
	Capabilities() []Capability
	Convert(ctx context.Context, in, out string, opts Options) error
}

Backend is the interface every converter must satisfy.

func All

func All() []Backend

All returns a snapshot of all backends from the global DefaultRegistry.

func Resolve

func Resolve(from, to string) (Backend, error)

Resolve returns the first backend from the global DefaultRegistry that can convert from→to. Returns ErrNoRoute if none found.

type Capability

type Capability struct {
	From    string
	To      string
	Cost    int // 1=fast, 5=slow/lossy
	Quality int // 0-100
	Lossy   bool
}

Capability declares a single From→To conversion that a backend can perform.

func AllCapabilities

func AllCapabilities() []Capability

AllCapabilities returns every declared capability across all backends in the global DefaultRegistry.

type ConvertError

type ConvertError struct {
	BackendName string
	From        string
	To          string
	Err         error
}

ConvertError wraps a backend error with routing context.

func (*ConvertError) Error

func (e *ConvertError) Error() string

func (*ConvertError) Is

func (e *ConvertError) Is(target error) bool

Is makes ConvertError satisfy errors.Is(err, ErrConvertFail) for retry logic.

func (*ConvertError) Unwrap

func (e *ConvertError) Unwrap() error

type OpType added in v0.1.1

type OpType string

OpType identifies a specific processing operation (e.g. "pdf.merge").

const (
	OpPDFMerge     OpType = "pdf.merge"
	OpPDFSplit     OpType = "pdf.split"
	OpPDFRotate    OpType = "pdf.rotate"
	OpPDFCrop      OpType = "pdf.crop"
	OpPDFOptimize  OpType = "pdf.optimize"
	OpPDFEncrypt   OpType = "pdf.encrypt"
	OpPDFDecrypt   OpType = "pdf.decrypt"
	OpPDFWatermark OpType = "pdf.watermark"
	OpPDFStamp     OpType = "pdf.stamp"
	OpPDFNUp       OpType = "pdf.nup"
	OpPDFBooklet   OpType = "pdf.booklet"
	OpPDFExtract   OpType = "pdf.extract"
	OpPDFValidate  OpType = "pdf.validate"
	OpPDFInfo      OpType = "pdf.info"
)

Processor operation constants. Each processor may support a subset.

func AllOperations added in v0.1.1

func AllOperations() []OpType

AllOperations returns a deduplicated list of all registered operation types across all processors in the global DefaultRegistry.

type Options

type Options struct {
	Quality   int
	StripMeta bool
	Workers   int
	ExtraArgs []string
	Named     map[string]string // "backend.key" → value
	Fonts     fonts.Config      // font preferences for PDF-producing backends
}

Options carries conversion parameters passed from CLI / config.

func (Options) Get

func (o Options) Get(backend, key string) string

Get returns the named option for a specific backend ("pandoc.wrap" etc.).

type ProcessParams added in v0.1.1

type ProcessParams map[string]string

ProcessParams carries operation-specific parameters as string key-value pairs. The Processor is responsible for parsing and validating each parameter before constructing its CLI invocation.

Common keys (operation-specific subsets):

pages   - page selection expression (e.g. "1-3,7")
angle   - rotation angle (multiple of 90)
mode    - operation mode (e.g. "page", "span", "bookmark", "create")
unit    - measurement unit (e.g. "pt", "mm", "cm", "in")
password - owner or user password (NEVER log or include in status)
n       - grid size for nup/booklet (2, 3, 4, 8, 9, 12, 16)
desc    - crop/stamp/watermark description string
value   - text or file path for stamp/watermark content

type ProcessRequest added in v0.1.1

type ProcessRequest struct {
	Op     OpType
	Inputs []string      // input file paths (1 for most ops, N for merge/nup/booklet)
	Output string        // output file or directory path
	Params ProcessParams // operation-specific parameters
	Opts   Options       // shared backend options (quality, extra args, etc.)
}

ProcessRequest describes a single processing operation to execute.

type ProcessResult added in v0.1.1

type ProcessResult struct {
	OutputPath string   // primary output file or directory
	Outputs    []string // all output files (for split/extract producing multiple files)
}

ProcessResult describes the outcome of a processing operation.

type Processor added in v0.1.1

type Processor interface {
	// Name returns the processor's unique identifier (e.g. "pdfcpu").
	Name() string

	// BinaryName returns the CLI binary this processor wraps (e.g. "pdfcpu").
	BinaryName() string

	// Operations returns the set of operation types this processor supports.
	Operations() []OpType

	// Process executes the requested operation. Implementations must return
	// ErrUnsupportedOp if the operation type is not in their supported set.
	Process(ctx context.Context, req ProcessRequest) (*ProcessResult, error)
}

Processor is the interface for backends that perform file-processing operations beyond simple from→to conversion (e.g. PDF merge, split, rotate). Processors are discovered and invoked separately from the conversion router/Engine pipeline.

func AllProcessors added in v0.1.1

func AllProcessors() []Processor

AllProcessors returns a snapshot of all Processors from the global DefaultRegistry.

func FindProcessor added in v0.1.1

func FindProcessor(op OpType) (Processor, error)

FindProcessor returns the first Processor from the global DefaultRegistry that supports the given operation. Returns ErrUnsupportedOp if none found.

func ProcessorsByOp added in v0.1.1

func ProcessorsByOp(op OpType) []Processor

ProcessorsByOp returns all Processors from the global DefaultRegistry that support the given operation.

type Registry added in v0.1.1

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

Registry is an isolated, concurrency-safe collection of backends and processors. Create one via NewRegistry for tests, TUI, or server adapters that need their own scope, independent of the process-global registry.

func NewRegistry added in v0.1.1

func NewRegistry(backends ...Backend) *Registry

NewRegistry creates a new empty Registry, optionally pre-populated with the given backends.

func (*Registry) All added in v0.1.1

func (r *Registry) All() []Backend

All returns a snapshot of all backends in this Registry.

func (*Registry) AllCapabilities added in v0.1.1

func (r *Registry) AllCapabilities() []Capability

AllCapabilities returns every declared capability across all backends in this Registry.

func (*Registry) AllOperations added in v0.1.1

func (r *Registry) AllOperations() []OpType

AllOperations returns a deduplicated, sorted list of all registered operation types across all processors in this Registry.

func (*Registry) AllProcessors added in v0.1.1

func (r *Registry) AllProcessors() []Processor

AllProcessors returns a snapshot of all Processors in this Registry.

func (*Registry) Find added in v0.1.1

func (r *Registry) Find(name string) (Backend, bool)

Find returns the first backend with the given name, if any.

func (*Registry) FindProcessor added in v0.1.1

func (r *Registry) FindProcessor(op OpType) (Processor, error)

FindProcessor returns the first Processor in this Registry that supports the given operation. Returns ErrUnsupportedOp if none found.

func (*Registry) ProcessorsByOp added in v0.1.1

func (r *Registry) ProcessorsByOp(op OpType) []Processor

ProcessorsByOp returns all Processors in this Registry that support the given operation.

func (*Registry) Register added in v0.1.1

func (r *Registry) Register(b Backend)

Register adds a backend to this Registry.

func (*Registry) RegisterProcessor added in v0.1.1

func (r *Registry) RegisterProcessor(p Processor)

RegisterProcessor adds a Processor to this Registry.

func (*Registry) Resolve added in v0.1.1

func (r *Registry) Resolve(from, to string) (Backend, error)

Resolve returns the first backend in this Registry that can convert from→to. Returns ErrNoRoute if none found.

Directories

Path Synopsis
backends
asciidoctor
Package asciidoctor provides AsciiDoc conversion via the asciidoctor binary.
Package asciidoctor provides AsciiDoc conversion via the asciidoctor binary.
calibre
Package calibre provides ebook conversion via the calibre ebook-convert binary.
Package calibre provides ebook conversion via the calibre ebook-convert binary.
csvkit
Package csvkit provides CSV/XLSX/JSON conversion via csvkit or xlsx2csv.
Package csvkit provides CSV/XLSX/JSON conversion via csvkit or xlsx2csv.
ffmpeg
Package ffmpeg provides audio/video conversion via the ffmpeg binary.
Package ffmpeg provides audio/video conversion via the ffmpeg binary.
figlet
Package figlet converts plain text to ASCII art via the figlet binary.
Package figlet converts plain text to ASCII art via the figlet binary.
imagemagick
Package imagemagick provides image conversion via ImageMagick (magick or convert).
Package imagemagick provides image conversion via ImageMagick (magick or convert).
jq
Package jq provides JSON formatting/transformation via the jq binary.
Package jq provides JSON formatting/transformation via the jq binary.
libjxl
Package libjxl provides JPEG XL conversion via cjxl and djxl.
Package libjxl provides JPEG XL conversion via cjxl and djxl.
libreoffice
Package libreoffice provides a backend that delegates to soffice (LibreOffice).
Package libreoffice provides a backend that delegates to soffice (LibreOffice).
pandoc
Package pandoc provides a backend that delegates conversions to pandoc.
Package pandoc provides a backend that delegates conversions to pandoc.
pdfcpu
Package pdfcpu provides PDF manipulation via the pdfcpu binary.
Package pdfcpu provides PDF manipulation via the pdfcpu binary.
plugin
Package plugin discovers and registers external convertr-* executables as backends.
Package plugin discovers and registers external convertr-* executables as backends.
resvg
Package resvg provides SVG to PNG rendering via resvg.
Package resvg provides SVG to PNG rendering via resvg.
tesseract
Package tesseract provides OCR via the tesseract binary.
Package tesseract provides OCR via the tesseract binary.
textutil
Package textutil provides a macOS-native backend using the textutil(1) command.
Package textutil provides a macOS-native backend using the textutil(1) command.
yq
Package yq provides YAML/JSON/TOML conversion via the yq binary.
Package yq provides YAML/JSON/TOML conversion via the yq binary.

Jump to

Keyboard shortcuts

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