golang text/template的用法: if, else, with
golang的text/template 包在使用的时候还是有些不便,特别是涉及到逻辑判断的时候。经过测试,发现下面这种写法是正确的。 1.2.1的环境下没有问题! 相关资料:https://gowalker.org/text/template 。 eq是一个函数。 package main import "text/template" import "os" func main() { type Inventory struct { Material string Count int } sweaters := Inventory{"axe", 0} html := ` "test").Parse("{{.Count}} items are made of {{.Material}}" {...阅读全文