el

package
v0.0.0-...-a264c11 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyTemplate

type AnyTemplate struct {
	Tmpl any
}

func (*AnyTemplate) Execute

func (t *AnyTemplate) Execute(data map[string]any) (interface{}, error)

func (*AnyTemplate) ExecuteAsString

func (t *AnyTemplate) ExecuteAsString(data map[string]any) string

ExecuteAsString 执行模板并返回字符串结果

func (*AnyTemplate) ExecuteFn

func (t *AnyTemplate) ExecuteFn(loadDataFunc func() map[string]any) (interface{}, error)

ExecuteFn 执行模板函数

func (*AnyTemplate) HasVar

func (t *AnyTemplate) HasVar() bool

func (*AnyTemplate) IsNotVar

func (t *AnyTemplate) IsNotVar() bool

func (*AnyTemplate) Parse

func (t *AnyTemplate) Parse() error

type ExprTemplate

type ExprTemplate struct {
	Tmpl    string
	Program *vm.Program
}

ExprTemplate 模板变量支持 这种方式 ${xx},使用expr表达式计算

func NewExprTemplate

func NewExprTemplate(tmpl string) (*ExprTemplate, error)

func (*ExprTemplate) Execute

func (t *ExprTemplate) Execute(data map[string]any) (interface{}, error)

func (*ExprTemplate) ExecuteAsString

func (t *ExprTemplate) ExecuteAsString(data map[string]any) string

ExecuteAsString 执行模板并返回字符串结果

func (*ExprTemplate) ExecuteFn

func (t *ExprTemplate) ExecuteFn(loadDataFunc func() map[string]any) (interface{}, error)

func (*ExprTemplate) HasVar

func (t *ExprTemplate) HasVar() bool

func (*ExprTemplate) IsNotVar

func (t *ExprTemplate) IsNotVar() bool

func (*ExprTemplate) Parse

func (t *ExprTemplate) Parse() error

type MixedTemplate

type MixedTemplate struct {
	Tmpl string
	// contains filtered or unexported fields
}

MixedTemplate 支持混合字符串和变量的模板,格式如 aa/${xxx}

func NewMixedTemplate

func NewMixedTemplate(tmpl string) (*MixedTemplate, error)

func (*MixedTemplate) Execute

func (t *MixedTemplate) Execute(data map[string]any) (interface{}, error)

func (*MixedTemplate) ExecuteAsString

func (t *MixedTemplate) ExecuteAsString(data map[string]any) string

func (*MixedTemplate) ExecuteFn

func (t *MixedTemplate) ExecuteFn(loadDataFunc func() map[string]any) (interface{}, error)

func (*MixedTemplate) ExecuteFnAsString

func (t *MixedTemplate) ExecuteFnAsString(loadDataFunc func() map[string]any) string

func (*MixedTemplate) HasVar

func (t *MixedTemplate) HasVar() bool

func (*MixedTemplate) IsNotVar

func (t *MixedTemplate) IsNotVar() bool

func (*MixedTemplate) Parse

func (t *MixedTemplate) Parse() error

type NotTemplate

type NotTemplate struct {
	Tmpl string
}

NotTemplate 原样输出

func (*NotTemplate) Execute

func (t *NotTemplate) Execute(data map[string]any) (interface{}, error)

func (*NotTemplate) ExecuteAsString

func (t *NotTemplate) ExecuteAsString(data map[string]any) string

ExecuteAsString 执行模板并返回字符串结果

func (*NotTemplate) ExecuteFn

func (t *NotTemplate) ExecuteFn(loadDataFunc func() map[string]any) (interface{}, error)

ExecuteFn 执行模板函数

func (*NotTemplate) HasVar

func (t *NotTemplate) HasVar() bool

func (*NotTemplate) IsNotVar

func (t *NotTemplate) IsNotVar() bool

func (*NotTemplate) Parse

func (t *NotTemplate) Parse() error

type Template

type Template interface {
	Parse() error
	Execute(data map[string]any) (interface{}, error)
	ExecuteFn(loadDataFunc func() map[string]any) (interface{}, error)
	ExecuteAsString(data map[string]any) string
	// Deprecated: Use HasVar instead.
	// IsNotVar 是否是模板变量
	IsNotVar() bool
	// HasVar 是否有变量
	HasVar() bool
}

func NewTemplate

func NewTemplate(tmpl any, params ...any) (Template, error)

NewTemplate 根据模板内容创建相应的模板实例 识别规则: 1. 如果是完整的单个表达式 ${...},创建 ExprTemplate 2. 如果包含变量但不是单个表达式,创建 MixedTemplate 3. 如果不包含变量,创建 NotTemplate 4. 如果不是字符串类型,创建 AnyTemplate

Jump to

Keyboard shortcuts

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