在 gopher 的日常开发工作中,时长会遇到写模板的需求。但大多数的 gopher(包括我在内)都不太了解 go template 的语法规则。 为了降低认知负担和试错成本,于是我开发了这个调试 Go 模板的工具。
- 下载代码并进入本项目目录
- 在本项目文件夹下编写模板文件:
a.html - 在本项目文件夹下编写模板数据:
a.json - 启动服务,本工具假设你已安装了 Go 开发环境
go run main.go- 访问 http://localhost:8080/view/a.html 即可看到渲染后的结果
- 安装本工具
# 从 gitee 安装
go get gitee.com/tering/go-template-debuger
go install gitee.com/tering/go-template-debuger
# 或从 github 安装
go get github.com/tering/go-template-debuger
go install github.com/tering/go-template-debuger- 在模板文件所在目录下执行命令:
go-template-debuger - 在模板文件所在目录下创建同名的 json 文件。例如: 模板文件为
a.html, 则数据文件为a.json - 访问 http://localhost:8080/view/<模板文件名> 即可看到渲染后的结果
具体语法规则请参考 Go 模板语法。