func Home(w http.ResponseWriter, r *staticAuth.AuthenticatedRequest) {
t, err := template.ParseFiles("index.html") //parse the html file homepage.html
if err != nil { // if there is an error
log.Print("template parsing error: ", err) // log it
}
err = t.Execute(w, nil) //execute the template and pass it the HomePageVars struct to fill in the gaps
if err != nil { // if there is an error
log.Print("template executing error: ", err) //log it
}
}
最佳答案
func Home(w http.ResponseWriter, r *staticAuth.AuthenticatedRequest) { t, err := template.ParseFiles("index.html") //parse the html file homepage.html if err != nil { // if there is an error log.Print("template parsing error: ", err) // log it } err = t.Execute(w, nil) //execute the template and pass it the HomePageVars struct to fill in the gaps if err != nil { // if there is an error log.Print("template executing error: ", err) //log it } }
在您的代码中,您检查并记录错误,然后继续并忽略错误。
关于go - 作为一个单元测试用例,应该为这样的函数编写什么。代码片段会有所帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48864836/