Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TemplateAttr ¶
type TemplateAttr func(t Templater)
type Templater ¶
type Templater interface {
New(content string, attrs ...TemplateAttr) Templater
Error() error
String() string
Bytes() []byte
Content() string
// contains filtered or unexported methods
}
TemplaterImpl 基于 struct tag 的模板渲染 通过 `template:"name"` 标签定义模板变量,自动将模板中的 {{name}} 替换为字段值
type TemplaterImpl ¶ added in v2.9.1
type TemplaterImpl struct {
// contains filtered or unexported fields
}
TemplaterImpl 基于 struct tag 的模板渲染 通过 `template:"name"` 标签定义模板变量,自动将模板中的 {{name}} 替换为字段值
func (*TemplaterImpl) Bytes ¶ added in v2.9.1
func (my *TemplaterImpl) Bytes() []byte
func (*TemplaterImpl) Content ¶ added in v2.9.1
func (my *TemplaterImpl) Content() string
func (*TemplaterImpl) Error ¶ added in v2.9.1
func (my *TemplaterImpl) Error() error
func (*TemplaterImpl) New ¶ added in v2.9.1
func (my *TemplaterImpl) New(content string, attrs ...TemplateAttr) Templater
New 根据结构体的 template tag 渲染模板 content 中使用 {{tagName}} 作为占位符,tagName 对应结构体字段上的 `template:"tagName"` 标签值
示例:
type Data struct {
Name string `template:"name"`
Age int `template:"age"`
}
tpl := "Hello {{name}}, you are {{age}} years old"
result := NewTemplateV2(tpl, Data{Name: "Tom", Age: 18}).String()
// => "Hello Tom, you are 18 years old"
func (*TemplaterImpl) String ¶ added in v2.9.1
func (my *TemplaterImpl) String() string
Click to show internal directories.
Click to hide internal directories.