我使用以下代码工作正常,但现在我想将模板打印到文件并尝试以下但出现错误
package main
import (
"html/template"
"log"
"os"
)
func main() {
t := template.Must(template.New("").Parse(`{{- range .}}{{.}}:
echo "from {{.}}"
{{end}}
`))
t.Execute(os.Stdout, []string{"app1", "app2", "app3"})
f, err := os.Create("./myfile")
if err != nil {
log.Println("create file: ", err)
return
}
err = t.Execute(f, t)
if err != nil {
log.Print("execute: ", err)
return
}
f.Close()
}
错误是:
execute: template: :1:10: executing "" at <.>: range can't iterate over {0xc00000e520 0xc00001e400 0xc0000b3000 0xc00009e0a2}
慕田峪4524236
PIPIONE
神不在的星期二
相关分类