Documentation
¶
Index ¶
- Variables
- func IsAvailable(b Backend, from, to string) bool
- func Register(b Backend)
- func RegisterProcessor(p Processor)
- func Wrap(name, from, to string, err error) error
- type Availabler
- type Backend
- type Capability
- type ConvertError
- type OpType
- type Options
- type ProcessParams
- type ProcessRequest
- type ProcessResult
- type Processor
- type Registry
- func (r *Registry) All() []Backend
- func (r *Registry) AllCapabilities() []Capability
- func (r *Registry) AllOperations() []OpType
- func (r *Registry) AllProcessors() []Processor
- func (r *Registry) Find(name string) (Backend, bool)
- func (r *Registry) FindProcessor(op OpType) (Processor, error)
- func (r *Registry) ProcessorsByOp(op OpType) []Processor
- func (r *Registry) Register(b Backend)
- func (r *Registry) RegisterProcessor(p Processor)
- func (r *Registry) Resolve(from, to string) (Backend, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoBinary = errors.New("binary not found") ErrNoRoute = errors.New("no conversion route") ErrConvertFail = errors.New("conversion failed") )
var DefaultRegistry = NewRegistry()
DefaultRegistry is the process-global registry used by existing init()-based backend registration. CLI adapters continue to use this by default.
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
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.
Types ¶
type Availabler ¶ added in v0.1.1
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.
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 ¶
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.
type ProcessParams ¶ added in v0.1.1
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
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
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
NewRegistry creates a new empty Registry, optionally pre-populated with the given backends.
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
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
AllProcessors returns a snapshot of all Processors in this Registry.
func (*Registry) FindProcessor ¶ added in v0.1.1
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
ProcessorsByOp returns all Processors in this Registry that support the given operation.
func (*Registry) RegisterProcessor ¶ added in v0.1.1
RegisterProcessor adds a Processor to this Registry.
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. |