当前位置:网站首页>Text Templates
Text Templates
2022-04-21 07:45:00 【Xiong Xiaohan】
effect
A template is a mixture of static text and action , For dynamically inserting content .
usage
initialization
t := template.New("template_name")
t, err := t.Parse("template_text")
if err != nil {
panic(err)
}
perhaps
t := template.New("template_name")
t = template.Must(t.Parse("template_text"))
template.Must Method implemented error Judgement and panic.
Implement an auxiliary method for creating templates :
CreateTemplate := func(name, text string) *template.Template {
return template.Must(template.New(name).Parse(text))
}
Variable display
t := CreateTemplate("t", "Value is {
{.}}\n")
t.Execute(os.Stdout, "some text")
t.Execute(os.Stdout, 5)
t.Execute(os.Stdout, []string{
"Go",
"Rust",
"C++",
"C#",
})
Value: some text
Value: 5
Value: [Go Rust C++ C#]
Key value pair display
t := CreateTemplate("t", "Name: {
{.Name}}\n")
t.Execute(os.Stdout, struct {
Name string
}{
"Jane Doe"})
t.Execute(os.Stdout, map[string]string{
"Name": "Mickey Mouse",
})
Name: Jane Doe
Name: Mickey Mouse
Logical presentation
t := CreateTemplate("t", "{
{if . -}} yes {
{else -}} no {
{end}}\n")
t.Execute(os.Stdout, "not empty")
t.Execute(os.Stdout, "")
yes
no
Traversal display
t := CreateTemplate("t", "Range: {
{range .}}{
{.}}、{
{end}}\n")
t.Execute(os.Stdout, []string{
"Go",
"Rust",
"C++",
"C#",
})
Range: Go、Rust、C++、C#、
版权声明
本文为[Xiong Xiaohan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210627176100.html
边栏推荐
猜你喜欢

论文阅读:Measuring the Impact of a Successful DDoS Attack on the Customer Behaviour of Managed DNS Servi

PLSQL developer 14 installation details

关于数据治理平台中数据仓库ODS、DW和DM概念理解

Ruijie eg easy gateway remote command execution vulnerability-1

H + background UI framework, click the button to create a new tab

论文阅读:Domain Name Encryption Is Not Enough: Privacy Leakage via IP-based Website Fingerprinting

分布式事务Seata
![Navicat连Oracle报错[No matching authentication protocol]](/img/16/4dd115fc5abc68f7d1ffa640165fd9.png)
Navicat连Oracle报错[No matching authentication protocol]

VS2019官方的免费打印控件

论文阅读:Social Media and Fake News in the 2016 Election
随机推荐
div点击折叠收缩
文件打包下载
MySQL数据库运行代码后,中文显示的是问号 ?
Principle and introduction of elk log analysis system
leetcode 704·二分查找
404 problem in idea configuration servlet solution
Outh2的基本概念
URL Parsing
VS2019官方的免费打印控件
PLSQL Developer 14安装详解
论文阅读:Cached and Confused: Web Cache Deception in the wild
laravel 打印sql
Command-Line
Configure MySQL remote access
2022-1-17至2022-1-30 迭代器模式
【WPF】数据模板选择器DataTemplateSelector
leetcode 209. 长度最小的子数组
Defining “Disinformation“(定义“虚假信息”)
Environment Variables
虚拟机安装kali 时的默认密码(官网vmx 文件源)