Golang - 函数"Execute"写入流的什么位置?



我是Go的初学者,我不明白在函数Execute流中写入数据"home.html"的调用在哪里。该 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")
}

这不是递归调用。它在"text/template"包中调用Template.Execute(而不是在"html/template"中调用Template.Execute)。这也是您将找到在编写器上实际写入字节的代码的地方。

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

最新更新