Documentation
¶
Overview ¶
Package report renders tabular results to HTML or PDF 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 or execs the CLI. The HTTP API is preferred whenever a facet URL or connection is configured: the server 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
- Variables
- func BuildArchive(srcDir string) ([]byte, error)
- func Render(ctx context.Context, server Server, data any, format, srcDir, entryFile string) ([]byte, error)
- func RenderCLI(ctx context.Context, data any, format, srcDir, entryFile string, ...) ([]byte, error)
- func RenderHTTP(ctx context.Context, server Server, data any, format, srcDir, entryFile string, ...) ([]byte, error)
- func TemplateDir() (string, error)
- type Column
- type Options
- type Payload
- type RenderOptions
- type Server
Constants ¶
const ( // PropertyURL names the facet server used when a report does not name one. PropertyURL = "facet.url" // PropertyConnection names the facet connection used when neither the // report nor facet.url names a server. PropertyConnection = "facet.connection" )
const EntryFile = "QueryReport.tsx"
EntryFile is the TSX component the embedded template renders with.
Variables ¶
ErrRendererUnavailable is returned when no facet server is configured and 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.
var SourceDir = os.Getenv("QUERY_REPORT_SOURCE_DIR")
SourceDir overrides the extracted template with a directory on disk, for developing the TSX without rebuilding the binary.
Functions ¶
func BuildArchive ¶
BuildArchive tars and gzips a template directory for the facet server.
func Render ¶
func Render( ctx context.Context, server Server, data any, format, srcDir, entryFile string, ) ([]byte, error)
Render sends the render to the configured server, falling back to the local binary only when none is configured.
func RenderCLI ¶
func RenderCLI( ctx context.Context, data any, format, srcDir, entryFile string, timeout time.Duration, ) ([]byte, error)
RenderCLI renders through the local facet binary. It is the fallback for when no server is configured; prefer RenderHTTP, which does not pay the cold-start cost on every run.
func RenderHTTP ¶
func RenderHTTP( ctx context.Context, server Server, data any, format, srcDir, entryFile string, options RenderOptions, ) ([]byte, error)
RenderHTTP renders data through a facet server. srcDir is the template directory; it is archived and sent with the request, so the server needs no prior knowledge of the template.
func TemplateDir ¶
TemplateDir returns a directory holding the report template, extracting the embedded copy on first use.
The location is content-addressed by the template's own hash, so the pnpm install and Vite build cached under .facet/ survive across renders and across restarts — a cold render costs roughly ten times a warm one — while a change to the template lands in a different directory and is never served stale.
Types ¶
type Column ¶
type Column struct {
Name string `json:"name"`
Type string `json:"type"`
Unit string `json:"unit,omitempty"`
}
Column is one facet DynamicTable column. Type drives the cell renderer, and must be one of facet's own names.
type Payload ¶
type Payload struct {
// Name is what facet writes the file as when the output path is a
// directory, so it doubles as the report's slug.
Name string `json:"name"`
Title string `json:"title"`
Subtitle string `json:"subtitle,omitempty"`
GeneratedAt string `json:"generatedAt"`
RowCount int `json:"rowCount"`
Truncated bool `json:"truncated,omitempty"`
Columns []Column `json:"columns"`
Rows []query.Row `json:"rows"`
}
Payload is what the TSX template is called with. It mirrors ReportData in QueryReport.tsx.
type RenderOptions ¶
RenderOptions carry the per-render knobs the archive does not.
type Server ¶
type Server struct {
BaseURL string
Token string
TimestampURL string
// Timeout bounds the render. Zero leaves it bounded by the facet server.
Timeout time.Duration
}
Server is a facet render service. The zero value means none is configured and rendering falls back to the local binary.
func ResolveServer ¶
ResolveServer picks the facet render service, preferring what the report asks for and falling back to the facet.url and facet.connection properties. A zero Server means none is configured and the local binary is used.