1 Star 0 Fork 0

飞的不是很熟练的猪/go-template

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 750 Bytes
一键复制 编辑 原始数据 按行查看 历史
飞的不是很熟练的猪 提交于 2022-04-04 19:49 +08:00 . ‘go语言模板学习’
package main
import (
"fmt"
"html/template"
"net/http"
)
func nest(w http.ResponseWriter,r *http.Request) {
// 不能写成template.ParseFiles("./ul.tmpl","./test.tmpl","./ol.tmpl")
// 因为是test.tmpl是主模板,ul.tmpl和ol.tmpl需要等主模板解析完之后在解析
t, err := template.ParseFiles("./test.tmpl","./ul.tmpl","./ol.tmpl")
if err != nil {
fmt.Printf("parse file failed err := %v",err)
}
mp := map[string]interface{}{
"name": "张大炮",
"sex": "女",
}
err = t.Execute(w, mp)
if err != nil {
fmt.Printf("execute file failed err := %v",err)
}
}
func main() {
http.HandleFunc("/",nest)
err := http.ListenAndServe(":9000", nil)
if err != nil {
fmt.Printf("listen address failed err = %v",err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/west-wood-does-not-live/go-template.git
git@gitee.com:west-wood-does-not-live/go-template.git
west-wood-does-not-live
go-template
go-template
master

搜索帮助