Help us shape the future of Go! Take the 2026 Go Developer Survey

template

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package template discovers, parses, and renders user-supplied Go templates against a sqlc GenerateRequest.

Index

Constants

View Source
const Extension = ".tmpl"

Extension is the required suffix for template files discovered under the configured templates directory.

View Source
const PartialPrefix = "_"

PartialPrefix marks template files that are parsed but not emitted as standalone outputs; they exist to be {{ template "_foo" . }}-included.

Variables

This section is empty.

Functions

func FuncMap

func FuncMap() template.FuncMap

FuncMap returns the template function map used by Render. Each call produces a fresh FuncMap because setStore/getStore close over a per-render map so cross-render state never leaks.

func Render

func Render(ctx Context) ([]*plugin.File, error)

Render walks ctx.TemplateDir for *.tmpl files, parses them all into a shared template set (so cross-file {{ template }} includes work), then executes every non-partial template against ctx. Output filenames are the template's path relative to TemplateDir, minus the .tmpl suffix, with the resulting string itself executed as a template.

Types

type Context

type Context struct {
	// Request is the raw sqlc GenerateRequest.
	Request *plugin.GenerateRequest
	// Options carries the user-supplied free-form extra map from sqlc.yaml.
	Options map[string]any
	// TemplateDir is the absolute or sqlc-relative directory that was
	// walked to discover templates. Exposed to templates for reference.
	TemplateDir string
	// SqlcVersion is hoisted from Request.SqlcVersion for convenience.
	SqlcVersion string
}

Context is the root value ('.') handed to every template and also used to render output-file names.

Jump to

Keyboard shortcuts

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