0

我是 Go 的初学者,我不明白在函数流中写入数据“home.html”的调用在哪里Execute。http.ResponseWriter 是很清楚但在函数中Execute我看不到像write .. fmt.Fprint..我这样的任何东西看递归Execute

http://golang.org/src/pkg/html/template/template.go?s=1245:1315#L40

//my Function
func homeHandler(c http.ResponseWriter, req *http.Request) {

var homeTempl = template.Must(template.ParseFiles("home.html"))

//here is my misunderstanding
homeTempl.Execute(c, req.Host)
//Thats consistent 
fmt.Fprint(c, "hallo")

}
4

1 回答 1

1

这不是递归调用。它在“text/template”包中调用 Template.Execute(不是“html/template”中的 Template.Execute)。这也是您可以找到实际在 Writer 上写入字节的代码的地方。

http://golang.org/src/pkg/text/template/exec.go?s=2630:2700#L95

于 2012-12-16T01:02:51.900 回答