facet

package
v0.1.101 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package facet renders React/TSX templates to HTML, PDF or PNG through facet.

facet is a TSX/React to Chromium print pipeline with no Go SDK, so a caller either POSTs to a `facet serve` instance (RenderHTTP) or execs the CLI (RenderCLI). Prefer the HTTP API whenever a server is configured: it keeps a warm Chromium worker pool, which is the difference between a ~1.4s render and a ~11s one, and keeps ~1GB of Chromium out of this process.

Index

Constants

This section is empty.

Variables

View Source
var ErrRendererUnavailable = errors.New("facet renderer unavailable")

ErrRendererUnavailable is returned when the facet binary is not installed. It is a distinct error so a deployment missing its renderer fails with an install hint rather than opaquely on every run.

Functions

func RenderCLI

func RenderCLI(ctx context.Context, req Request) ([]byte, error)

RenderCLI renders through the local facet binary, running `facet <format> <entry> --data <file> -o <file>` in Request.SrcDir.

func RenderHTTP

func RenderHTTP(ctx context.Context, server Server, req Request) ([]byte, error)

RenderHTTP renders through a facet server. The template directory is archived and sent with the request, so the server needs no prior knowledge of it. Request.Timeout wins over Server.Timeout.

Types

type Request

type Request struct {
	// SrcDir is the template directory; Entry is the entry file relative to it.
	SrcDir, Entry string
	Data          any
	// Format is html, pdf or png.
	Format string
	// Runtime names a prebuilt facet runtime (name, name@version or folder).
	// Only the CLI can select one.
	Runtime string
	// Options are extra render options: `--<kebab-key>` flags for the CLI,
	// merged into the options JSON for the server.
	Options map[string]any
	Timeout time.Duration
}

Request is one render.

type Server

type Server struct {
	BaseURL      string
	Token        string
	TimestampURL string

	// Timeout bounds a render whose Request sets none. Zero leaves it bounded by
	// the facet server.
	Timeout time.Duration
}

Server is a facet render service.

Jump to

Keyboard shortcuts

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