In Development Package, API may change between versions.

import "github.com/egdaemon/eg/runtime/x/wasi/egtemplate"

Package egtemplate provides helpers for rendering text templates.

func Reader

func Reader(t Executor, data any) io.Reader

Reader returns a reader of the template rendered with the given data. rendering is deferred until the first Read, so values the template computes can depend on work completed after the reader was created. rendering errors are reported by Read, which lets the result be handed to anything that consumes an io.Reader (e.g. egfs.Install) without partial output.

type Executor

Executor is the rendering behavior of a template, satisfied by *text/template.Template and *html/template.Template.

type Executor interface {
    Execute(w io.Writer, data any) error
}
⬤