exporttemplate

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package exporttemplate provides templated renderer adapters for go-export.

Renderer is disabled by default; set Renderer.Enabled to true and supply Templates (TemplateExecutor). The default template name is "export".

Templates can use Go's html/template or Django/Pongo2-style syntax via a compatible executor wrapper (for example, wrapping pongo2 or github.com/gofiber/template/django/v3). BufferedStrategy is the default and enforces bounded buffering (DefaultMaxBufferedRows); StreamingStrategy streams rows through a channel so templates can range over .Rows without loading all rows into memory (channel-based rows work best with range blocks).

For server-side PDF output, pair the template renderer with adapters/pdf (wkhtmltopdf or a custom chromedp/rod engine).

Index

Constants

View Source
const DefaultMaxBufferedRows = 10000

DefaultMaxBufferedRows bounds template buffering by default.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferedStrategy

type BufferedStrategy struct {
	MaxRows int
}

BufferedStrategy collects rows in memory before executing the template. MaxRows controls the maximum number of rows buffered before returning an error.

func (BufferedStrategy) Render

type Renderer

type Renderer struct {
	Enabled      bool
	Templates    TemplateExecutor
	TemplateName string
	Strategy     Strategy
}

Renderer renders templated HTML exports.

func (Renderer) Render

Render executes a template with the provided rows.

type Strategy

type Strategy interface {
	Render(ctx context.Context, tmpl TemplateExecutor, name string, schema export.Schema, rows export.RowIterator, w io.Writer, opts export.RenderOptions) (export.RenderStats, error)
}

Strategy renders template output with a selectable buffering strategy.

type StreamingStrategy

type StreamingStrategy struct{}

StreamingStrategy streams rows into the template via a channel.

func (StreamingStrategy) Render

type TemplateData

type TemplateData struct {
	Schema   export.Schema `json:"schema"`
	Columns  []string      `json:"columns"`
	Rows     []export.Row  `json:"rows"`
	RowCount int           `json:"row_count"`
	TemplateMeta
}

type TemplateExecutor

type TemplateExecutor interface {
	ExecuteTemplate(w io.Writer, name string, data any) error
}

TemplateExecutor executes a named template with data.

type TemplateMeta

type TemplateMeta struct {
	TemplateName string         `json:"template_name,omitempty"`
	Layout       string         `json:"layout,omitempty"`
	Title        string         `json:"title,omitempty"`
	Definition   string         `json:"definition,omitempty"`
	Generated    string         `json:"generated,omitempty"`
	GeneratedAt  time.Time      `json:"generated_at,omitempty"`
	ChartConfig  any            `json:"chart_config,omitempty"`
	Theme        map[string]any `json:"theme,omitempty"`
	Header       map[string]any `json:"header,omitempty"`
	Footer       map[string]any `json:"footer,omitempty"`
	Data         map[string]any `json:"data,omitempty"`
}

TemplateData is the context passed to templates.

Directories

Path Synopsis
go-template module

Jump to

Keyboard shortcuts

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