template

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package template provides template rendering for ctxweaver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template wraps a parsed template for statement generation.

func MustParse

func MustParse(text string) *Template

MustParse parses a template string and panics on error.

func Parse

func Parse(text string) (*Template, error)

Parse parses a template string.

func (*Template) Raw

func (t *Template) Raw() string

Raw returns the original template string.

func (*Template) Render

func (t *Template) Render(vars Vars) (string, error)

Render executes the template with the given variables.

type Vars

type Vars struct {
	// Ctx is the expression to access context.Context (e.g., "ctx", "c.Request().Context()")
	Ctx string
	// CtxVar is the name of the context parameter variable (e.g., "ctx", "c")
	CtxVar string
	// FuncName is the fully qualified function name (e.g., "(*pkg.Service).Method")
	FuncName string
	// PackageName is the package name (e.g., "service")
	PackageName string
	// PackagePath is the full import path (e.g., "github.com/example/myapp/pkg/service")
	PackagePath string
	// FuncBaseName is the function name without package/receiver (e.g., "Method")
	FuncBaseName string
	// ReceiverType is the receiver type name (empty if not a method)
	ReceiverType string
	// ReceiverVar is the receiver variable name (empty if not a method)
	ReceiverVar string
	// IsMethod indicates whether this is a method
	IsMethod bool
	// IsPointerReceiver indicates whether the receiver is a pointer
	IsPointerReceiver bool
	// IsGenericFunc indicates whether the function has type parameters
	IsGenericFunc bool
	// IsGenericReceiver indicates whether the receiver type has type parameters
	IsGenericReceiver bool
}

Vars holds the variables available in templates.

func BuildVars

func BuildVars(df *dst.File, decl *dst.FuncDecl, pkgPath string, carrier config.CarrierDef, varName string) Vars

BuildVars constructs a Vars instance from AST nodes and carrier definition. This function extracts all necessary information from the function declaration and builds template variables that can be used for statement rendering.

Jump to

Keyboard shortcuts

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